DEV Community

John Au-Yeung
John Au-Yeung

Posted on • Originally published at thewebdev.info

3

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more