let str = "Please locate where 'locate' occurs!";
str.indexOf("locate");
//it will returns the index of (the position of) the first occurrence of a specified text in a string:
// >> 7
//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
function find(needle, haystack) {
var results = [];
var idx = haystack.indexOf(needle);
while (idx != -1) {
results.push(idx);
idx = haystack.indexOf(needle, idx + 1);
}
return results;
}
Code language: JavaScript (javascript)