Answer the question
In order to leave comments, you need to log in
How to remove an element from an array if you know its ID?
There is an array of objects, each of which has ID properties (starting from one). What is the best way to remove an element from an array by its id?
PS it's about angular + fullcalendar.
Answer the question
In order to leave comments, you need to log in
var someArray = [{id: 1}, {id: 2}, {id: 3}],
idToDelete = 2
someArray.forEach(function(el, i) {
if (el.id == idToDelete) someArray.splice(i, 1)
})
console.log(someArray)
// [{id: 1}, {id: 3}]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question