The match method can be used in JavaScript.
function findCharIndex() { haystack = "this is a string" needle = "a" // "is","string" let matchWord = haystack.match(needle); if(!matchWord){ return -1; } return matchWord.index; }; console.log(findCharIndex());