let aUsers=[{"name":"goku"},{"name":"cell"},{"name":"vegeta"},{"name":"freezer"}]
aUsers.forEach((user,i)=>{
if(user.name=="cell" || user.name=="freezer"){
aUsers.splice(i,1); //this causes a problem..
}
})
console.log(aUsers);
I know that I should use filter
, but I don't know how to get my elements to be removed
from the array
at the same time my foreach
runs.
I would know how to solve this problem, but after running the foreach
, maybe there is a better way to do it.
how can I do it?