javascript index of with var

Solutions on MaxInterview for javascript index of with var by the best coders in the world

showing results for - "javascript index of with var"
Ian
04 Aug 2018
1var indices = [];
2var array = ['a', 'b', 'a', 'c', 'a', 'd'];
3var element = 'a';
4var idx = array.indexOf(element);
5while (idx != -1) {
6  indices.push(idx);
7  idx = array.indexOf(element, idx + 1);
8}
9console.log(indices);
10// [0, 2, 4]
11