This topic has been widely asked and discussed and yet I still cannot find a solution for my particular problem.
I need to create a function that returns the index for the first occurrence of a character in a string..seems simple enough, however I cannot use any built in functions such as; indexof,lastIndexOf,search,startsWith,findIndex, essentially anything that would make this easier and stop me from asking a question that has so clearly already been answered.
So far what I have is something like this:
function searchIndex(str,index){
let x = str.charAt(index);
console.log(x);
}
I understand that charAt requires an index, now my question is is there anyway I can make this work? My thinking when writing this was, if I throw in a string such as 'abc' and give an index of 0, it would return 'a', however I get an error that says charAt is not a function. Which tells me my thinking was incorrect and that I cant just use index parameter from the function as an index for charAt.
Any help or direction to solve this problem would be greatly appreciated.
edited charAT to charAt, apologies.
charAtnotcharATstr.lengthto return the length of the string, and you can access individual characters likestr[i]. See stackoverflow.com/questions/1966476/…str.indexOf(char)should works. ``` var str = 'abcabc'; str.indexOf('a'); // => 0 ```