Remove array element based on object property

后端 未结 12 770
臣服心动
臣服心动 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:17

    Say you want to remove the second object by it's field property.

    With ES6 it's as easy as this.

    myArray.splice(myArray.findIndex(item => item.field === "cStatus"), 1)
    

提交回复
热议问题