Remove array element based on object property

后端 未结 12 772
臣服心动
臣服心动 2020-11-22 08:19

I have an array of objects like so:

var myArray = [
    {field: \'id\', operator: \'eq\', value: id}, 
    {field: \'cStatus\', operator: \'eq\', value: cSta         


        
12条回答
  •  旧时难觅i
    2020-11-22 09:12

    var myArray = [
        {field: 'id', operator: 'eq', value: id}, 
        {field: 'cStatus', operator: 'eq', value: cStatus}, 
        {field: 'money', operator: 'eq', value: money}
    ];
    console.log(myArray.length); //3
    myArray = $.grep(myArray, function(element, index){return element.field == "money"}, true);
    console.log(myArray.length); //2
    

    Element is an object in the array. 3rd parameter true means will return an array of elements which fails your function logic, false means will return an array of elements which fails your function logic.

提交回复
热议问题