0

I'm able to remove the duplicates from the JSON given below :

var testJSON=[
    {
        "target": "300.0",
        "valueObj": {
            "id": 2538
        }
    },
    {
        "target": "400.0",
        "valueObj": {
            "id": 2539
        }
    },
    {
        "target": "300.0",
        "valueObj": {
            "id": 2538
        }
    },
    {
        "target": "400.0",
        "valueObj": {
            "id": 2539
        }
    },
    {
        "target": "12.23",
        "valueObj": {
            "id": 2540
        }
    }
]

using underscore _uniq property as:

_.uniq(testJSON ,'valueObj.id');

which returns only unique property ie.,

    {
        "target": "300.0",
        "valueObj": {
            "id": 2538
        }
    }

But not displaying other objects . The result that I'm expecting..

[
        {
            "target": "300.0",
            "valueObj": {
                "id": 2538
            }
        },
        {
            "target": "400.0",
            "valueObj": {
                "id": 2539
            }
        },          

        {
            "target": "12.23",
            "valueObj": {
                "id": 2540
            }
        }
    ]
forgottofly
  • 2,729
  • 11
  • 51
  • 93
  • possible duplicate http://stackoverflow.com/questions/9923890/removing-duplicate-objects-with-underscore-for-javascript – Sami Feb 02 '16 at 09:04

1 Answers1

0

Solved by doing this..

   var testJSON = _.uniq(testJSON, function (item: any, key, a) {
                     return item.valueObj.id;
                    });
forgottofly
  • 2,729
  • 11
  • 51
  • 93