var arrayElements = [1,2,3,4,2]; console.log(arrayElements); //[1, 2, 3, 4, 2] arrayElements.forEach((element,index)=>{ if(element==2) arrayElements.splice(index,1); }); console.log(arrayElements); //[1, 3, 4]