How to remove a specific item from an array in es6

 How to remove a specific item 9 from an array arr?

There are different methods which we can use to remove elements from an arrays


const arr = [1, 2, 7, 9, 19];
const index = arr.indexOf(9);
if (index > -1) { arr.splice(index, 1); }

If we want new array without specific value
const result = arr.filter((item) =>{ 
 return item !== 9;
});

Comments

Popular posts from this blog

world tourism guide Template

Es6 how to check if value is not null or undefined?