How to remove a specific item from an array

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

css :Custom Horizontal Rules

Hindi Toolkit