remove object from array of objects based on object property javascript 1

remove object from array of objects based on object property javascript

var myArray = [
    {field: 'id', operator: 'eq', value: id}, 
    {field: 'cStatus', operator: 'eq', value: cStatus}, 
    {field: 'money', operator: 'eq', value: money}
];

// only keep objects in array where obj.field !== 'money'
myArray = myArray.filter(function( obj ) {
    return obj.field !== 'money';
});

Here is what the above code is Doing:
1. Create an array of objects
2. Filter the array of objects to only keep objects where obj.field !== ‘money’
3. Return the filtered array

Similar Posts