I have an array of objects like so:
var myArray = [
{field: 'id', operator: 'eq', value: id},
{field: 'cStatus', operator: 'eq', value: cStatus},
{field: 'money', operator: 'eq', value: money}
];
How do I remove a specific one based on its property?
e.g. How would I remove the array object with 'money' as the field property?
Say you want to remove the second object by it's field property.
With ES6 it's as easy as this.
Following is the code if you are not using jQuery. Demo
You can also use underscore library which have lots of function.
Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support
Based on some comments above below is the code how to remove an object based on a key name and key value
Iterate through the array, and
splice
out the ones you don't want. For easier use, iterate backwards so you don't have to take into account the live nature of the array:jAndy's solution is probably best, but if you can't rely on filter you could do something like: