DEV Community

John Au-Yeung
John Au-Yeung

Posted on • Originally published at thewebdev.info

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

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;
});
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (1)

Collapse
 
djmisterjon profile image
DjMisterJon

cpu killer, go to jail