如何使 JSON 数组唯一 [英] How to make a JSON array unique
问题描述
可能的重复:
数组唯一值
使用 jQuery 从 JSON 数组中获取唯一结果
我有一个这样的 JSON 字符串
<预><代码>[对象 { id="38",product="foo"},对象 { id="38",product="foo"},对象 { id="38",product="foo"},对象 { id="39",product="bar"},对象 { id="40",product="hello"},对象 { id="40",product="hello"}]此 JSON 数组中有重复值..如何使此 JSON 数组像这样唯一
<预><代码>[对象 { id="38",product="foo"},对象 { id="39",product="bar"},对象 { id="40",product="hello"}].我正在寻找使用较少迭代的建议,Jquery $.inArray
在这种情况下不起作用.
欢迎使用任何第三方库的建议.
检查以下 SO 问题中的解决方案:
您必须遍历数组并创建一个包含唯一值的新数组.
Possible Duplicate:
Array unique values
Get unique results from JSON array using jQuery
Im having a JSON string like this
[
Object { id="38",product="foo"},
Object { id="38",product="foo"},
Object { id="38",product="foo"},
Object { id="39",product="bar"},
Object { id="40",product="hello"},
Object { id="40",product="hello"}
]
There are duplicate values in this JSON array..how can i make this JSON array unique like this
[
Object { id="38",product="foo"},
Object { id="39",product="bar"},
Object { id="40",product="hello"}
]
.Im looking for a suggestion that uses less iterations,
Jquery $.inArray
is not working in this case.
Suggestion to use any third party libraries are welcome.
Check the solution in the following SO question:
Get unique results from JSON array using jQuery
You'll have to iterate through your array and create a new array which contains unique values.
这篇关于如何使 JSON 数组唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!