How to remove specific item from an array in ES6?

September 28, 2022 No comments javascript es remote array item

Introduction

In JavaScript ES6, we may wish to remove items from an array.

We'll examine how to remove an item from an array in this tutorial.

Remove an item from an array in ES6

To remove specific item from an array in ES6 we need to use array.filter(...) function.

let array = [8, 5, 2, 0, 9];

array = array.filter(item => item !== 5);

console.log(array);  // array = [8, 2, 0, 9]

Using array.filter(...) we simple remove unwanted items.

Note that: this method generates a new array rather than altering the existing one.

Conclusion

To remove specific item from an array in ES6 we can use array.filter(...) method to filter unwanted items and generate a new array with less elements.

{{ message }}

{{ 'Comments are closed.' | trans }}