Compare two arrays of objects and remove items in the second one that have the same property value

后端 未结 8 794
温柔的废话
温柔的废话 2020-12-06 01:55

All I need to do is compare two arrays of objects and remove items in the second one that have the same property value. For example:

var a = [{\'name\':\'bob         


        
8条回答
  •  一整个雨季
    2020-12-06 02:16

    You just need to break the inner loop when a match is found:

    if (a[i].name == b[j].name) {
        b.splice(j, 1);
        break;
    }
    

提交回复
热议问题