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

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay