How Can I Completely Remove An Object From An Array In Javascript?
I have been using the following code: formData.objectiveDetails.push(emptyObjectiveDetail); This pushes a new emptyObjectiveDetail object onto the end of an array called objective
Solution 1:
formData.objectiveDetails.splice(5, 1)
First argument is the array index and the second the number of items to remove starting from that index.
Solution 2:
You can use Splice to remove the object from the array. Something like this:-
formData.objectiveDetails.splice(5, 1)
Solution 3:
Using underscore.js
objectiveDetails = _.without(objectiveDetails, _.findWhere(arr, {id: 5}));
Post a Comment for "How Can I Completely Remove An Object From An Array In Javascript?"