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

后端 未结 8 793
温柔的废话
温柔的废话 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:10

    Try this:

    You are starting loop from the 0.

    for (var i = 0, len = a.length; i < len; i++) {
            for (var j = 0, len = b.length; j < len-1; j++) {
                if (a[i].name == b[j].name) {
                    b.splice(j, 1);
                }
            }
        }
    

    Fiddle Demo

提交回复
热议问题