0

can somebody help me remove object from array having some duplicate properties.

var data = [{
    "IDPOSITION": "1",
    "LATITUDE": "5.35961",
    "LONGITUDE": "-3.10095",
    "IDUSAGER": "1",
    "DATECREATION": "2013-10-12 21:53:09"
}, {
    "IDPOSITION": "2",
    "LATITUDE": "5.35961",
    "LONGITUDE": "-4.00095",
    "IDUSAGER": "1",
    "DATECREATION": "2013-10-12 21:53:51"
}, {
    "IDPOSITION": "3",
    "LATITUDE": "5.35961",
    "LONGITUDE": "-4.00095",
    "IDUSAGER": "1",
    "DATECREATION": "2013-10-12 21:53:53"
}];

I need to remove objects having same couple of (LATITUDE, LONGITUDE). In the example above data[1] and data[2] are duplicate from criteras (LATITUDE, LONGITUDE)

1 Answer 1

2

For example:

_.uniq(data, function(x) { return x.LATITUDE + "/" + x.LONGITUDE })

Basically, you provide a function that is supposed to return a hash value based on selected properties.

Sign up to request clarification or add additional context in comments.

3 Comments

thx for return x.LATITUDE + "/" + x.LONGITUDE. I didn't know about "/"
@MarcelDjaman: there's nothing special about / here - it's just a random char I used to create a string hash.
Always thought about return property. thanks for pointing me about the hash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.