DEV Community

Calvin
Calvin

Posted on

Reading Snippets [24]

IndexOf() method returns the position of the first occurrence of a value in a string.

Example:


let str = "I love the taste of sugar in the morning"
let noun = str.indexOf("sugar")
console.log(noun);
// Output of 20



Enter fullscreen mode Exit fullscreen mode

Top comments (0)