Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

Remove first matching item in a collection

$
0
0

Given a collection, how can I remove only the first item that matches a condition?

For example, given this collection:

[
  { id: 1, name: "don" },
  { id: 2, name: "don" },
  { id: 3, name: "james" },
  { id: 4, name: "james" }
]

Filter out the first result that matches { name: "james" }.

Result:

[
  { id: 1, name: "don" },
  { id: 2, name: "don" },
  { id: 4, name: "james" }
]

Viewing all articles
Browse latest Browse all 138163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>