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

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

    compare and remove in array of object.Typically array of object data type may be typeOf is object.So that we need to convert into JSON stringify and then check condition..

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

提交回复
热议问题