Underscore: Remove object having some duplicate properties

对着背影说爱祢 提交于 2019-12-08 12:41:51

问题


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:


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.



来源:https://stackoverflow.com/questions/21426994/underscore-remove-object-having-some-duplicate-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!