Answers for "javascript index of with var"

1

javascript index of with var

var indices = [];
var array = ['a', 'b', 'a', 'c', 'a', 'd'];
var element = 'a';
var idx = array.indexOf(element);
while (idx != -1) {
  indices.push(idx);
  idx = array.indexOf(element, idx + 1);
}
console.log(indices);
// [0, 2, 4]
Posted by: Guest on February-08-2020

Code answers related to "javascript index of with var"

Code answers related to "Javascript"

Browse Popular Code Answers by Language