var people = ['alex','jason','matt'];
people.forEach(function(p){
if(p.length > 4){
//REMOVE THIS PERSON or pop it out of the list or whatever
}
});
console.log(people) //should return ['alex','matt']
I want to remove an element out of the list, using this forEach loop.
You shouldn’t modify the array you’re looping on. You can produce a new one, though:
Why you shouldn’t modify array you’re looping.