How to determine if Javascript array contains an object with an attribute that equals a given value?

后端 未结 25 1269
借酒劲吻你
借酒劲吻你 2020-11-22 08:17

I have an array like

vendors = [{
    Name: \'Magenic\',
    ID: \'ABC\'
  },
  {
    Name: \'Microsoft\',
    ID: \'DEF\'
  } // and so on... 
];
         


        
25条回答
  •  悲&欢浪女
    2020-11-22 08:50

    var without2 = (arr, args) => arr.filter(v => v.id !== args.id); Example:

    without2([{id:1},{id:1},{id:2}],{id:2})

    Result: without2([{id:1},{id:1},{id:2}],{id:2})

提交回复
热议问题