I have an array like this
var array = [1,2,3,4,5,6,7,8,9,10];
Looping code is like this using _.each function in underscore.js
_.each(array,function(item,index){
console.log(item);
});
But I want remove some items in array when looping. For example I need to remove number 5 from array and loop does not print number 5. The question is, is it possible to remove items in array when looping on this array?
.each()because (again I'm not sure about underscore, but for some other equivalents) the length of the array may be cached at the beginning so then if you remove items the iterator will run off the end. It's no problem if iterating with a traditionalforloop.i--whenever he removes the current element ;)