Remove array element based on object property

后端 未结 12 1093
臣服心动
臣服心动 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条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 09:10

    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:

    for (var i = myArray.length - 1; i >= 0; --i) {
        if (myArray[i].field == "money") {
            myArray.splice(i,1);
        }
    }
    

提交回复
热议问题