World Languages, asked by ygaurav7552, 1 year ago

JavaScript to find the position of the first occurrence of a text in a string.

Answers

Answered by shreyapatil1
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 Anonymous
6

Hi

function findFirstOccurrence (str, word) {

 return str.indexOf(word);

}

console.log(findFirstOccurrence('Hello my name is Ajay.', 'Ajay'));

Similar questions