JavaScript to find the position of the first occurrence of a text in a string.
Answers
Answered by
0
var string = "www.google.com.sdg.jfh.sd",
preString = "sdg",
searchString = ".s",
preIndex = string.indexOf(preString),
searchIndex = preIndex + string.substring(preIndex).indexOf(searchString);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I hope it may helpful to u
Answered by
6
Hi
function findFirstOccurrence (str, word) {
return str.indexOf(word);
}
console.log(findFirstOccurrence('Hello my name is Ajay.', 'Ajay'));
Similar questions