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

前端 未结 18 1072
没有蜡笔的小新
没有蜡笔的小新 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:09

    I found this solution using filter and some.

    resultFilter = (firstArray, secondArray) => {
      return firstArray.filter(firstArrayItem =>
        !secondArray.some(
          secondArrayItem => firstArrayItem._user === secondArrayItem._user
        )
      );
    };

提交回复
热议问题