Find duplicate values in objects with Javascript

前端 未结 5 779
[愿得一人]
[愿得一人] 2021-01-12 01:47

I\'ve been trying to work out a problem I\'m having. I have an array with objects in it, like this:

var array = [
  {
    name: \"Steven Smith\",
    Country         


        
5条回答
  •  孤独总比滥情好
    2021-01-12 02:23

    Quick answer I came up now:

       
    let result = [];
    
    for(let item of array)
    {
        for(let checkingItem of array)
        {
          if(array.indexOf(item) != array.indexOf(checkingItem) &&
            (item.name == checkingItem.name || item.Age == checkingItem.Age))
          {
            if(result.indexOf(checkingItem) == -1)
            {
              result.push(checkingItem);
            }
    
          }
       }
    }
    
    console.log(result);

提交回复
热议问题