JSFiddle - React, Tailwind, and code Playground

by humanzing

JavaScript

console.log(find_all_index("w", "Hello world, welcome to the universe."))

function find_all_index(str, text) {
	var i = 0;
	var arr = []
	var last = 0;
  var n = true;
  while (n == true) {
    i++;
    var no = text.indexOf(str);
    if (no == -1) {
      n = -1;
    } else {
      arr.push(no + last + 1);
      last = no + 1;
      text = text.slice(no + 1);
    }
    if (i > 25) {
      n = -1;
    }
  }
  return arr;
}