How to get the difference between two arrays of objects in JavaScript

前端 未结 18 1410
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 04:45

I have two result sets like this:

// Result 1
[
    { value: \"0\", display: \"Jamsheer\" },
    { value: \"1\", display: \"Muhammed\" },
    { value: \"2\",         


        
18条回答
  •  暖寄归人
    2020-11-22 05:19

    import differenceBy from 'lodash/differenceBy'
    
    const myDifferences = differenceBy(Result1, Result2, 'value')
    

    This will return the difference between two arrays of objects, using the key value to compare them. Note two things with the same value will not be returned, as the other keys are ignored.

    This is a part of lodash.

提交回复
热议问题