javascript index of with var

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

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
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