How to remove element from array in forEach loop? How to remove element from array in forEach loop? javascript javascript

How to remove element from array in forEach loop?


It looks like you are trying to do this?

Iterate and mutate an array using Array.prototype.splice

var pre = document.getElementById('out');function log(result) {  pre.appendChild(document.createTextNode(result + '\n'));}var review = ['a', 'b', 'c', 'b', 'a'];review.forEach(function(item, index, object) {  if (item === 'a') {    object.splice(index, 1);  }});log(review);
<pre id="out"></pre>