I have an array of objects:
[{"value":"14","label":"7"},{"value":"14","label":"7"},{"value":"18","label":"7"}]
How I can delete this item {"value":"14","label":"7"} resulting in the new array:
{"value":"14","label":"7"}
[{"value":"14","label":"7"},{"value":"18","label":"7"}]
?
In ES6 (or using es6-shim) you can use Array.prototype.findIndex along with Array.prototype.splice:
arr.splice(arr.findIndex(matchesEl), 1); function matchesEl(el) { return el.value === '14' && el.label === '7'; }
Or if a copy of the array is ok (and available since ES5), Array.prototype.filter's the way to go:
var withoutEl = arr.filter(function (el) { return !matchesEl(el); });
2.1m questions
2.1m answers
60 comments
57.0k users