Answers for "javascript find all occurrences in string"

0

javascript find all occurrences in string

var str = "I learned to play the Ukulele in Lebanon."
var regex = /le/gi, result, indices = [];
while ( (result = regex.exec(str)) ) {
    indices.push(result.index);
}
console.log(indices) // => [2, 25, 27, 33]
//find all occurence of le and return the return an array of the indeces
Posted by: Guest on May-11-2021

Code answers related to "javascript find all occurrences in string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language