本文介绍了下划线:删除具有某些重复属性的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮我从数组中删除具有某些重复属性的对象吗?
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"
}];
我需要删除具有相同(纬度、经度)的对象.在上面的示例中,数据[1] 和数据[2] 与标准(纬度、经度)重复
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)
推荐答案
例如:
_.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.
这篇关于下划线:删除具有某些重复属性的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!