Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to remove element from array in foreach javascript

var pre = document.getElementById('out');

function log(result) {
  pre.appendChild(document.createTextNode(result + '
'));
}

var review = ['a', 'a', 'b', 'c', 'b', 'a', 'a'],
  index = review.indexOf('a');

while (index !== -1) {
  review.splice(index, 1);
  index = review.indexOf('a');
}

log(review);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #remove #element #array #foreach #javascript
ADD COMMENT
Topic
Name
9+8 =