我想要一个数组,它将获取我的 json Ex 的重复键:
var catalog=[
{ ip: 'ipId_1', name: '192.160.121.11' },
{ ip: 'ipId_dyn_1_0', name: '192.160.121.12' },
{ ip: 'ipId_dyn_1_1', name: '192.160.121.12' }
];
由于 192.160.121.12 重复,我想要一个像 [ipId_dyn_1_0, ipId_dyn_1_1] 这样的数组,
到目前为止尝试过(小提琴演示):
var categories =[];
var dup= [];
$.each(catalog, function(index, value) {
console.log( categories+''+value.name);
if ($.inArray(value.name, categories) == -1) {
categories.push(value.name);
}else{
dup.push(value.ip);
console.log(value.ip);
}
});
console.log(categories);
console.log(dup);