Categories
JavaScript Answers

How to remove item from array using its name / value with JavaScript?

Spread the love

To remove item from array using its name / value with JavaScript, we use the filter method.

For instance, we write

const COUNTRY_ID = "AL";

countries.results = countries.results.filter((el) => {
  return el.id !== COUNTRY_ID;
});

to call filter with a callback to return an array within the countries.results array without the object with id not equal to COUNTRY_ID.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *