JS 如何删除二维数组的重复项?
数组 array=[["aa","bb","cc"],["aa","bb","cc"],["b","b","v"]]
删除后数组变为array2=[["aa","bb","cc"],["b","b","v"]]
JS 如何删除二维数组的重复项?
数组 array=[["aa","bb","cc"],["aa","bb","cc"],["b","b","v"]]
删除后数组变为array2=[["aa","bb","cc"],["b","b","v"]]
上面的代码都不是最优雅的,关键在于你对js对象模型(JSON)的理解,如果能够和JAVA的HashMap联系起来,就容易理解了。
[code="javascript"]
var arr = [["aa","bb","cc"],["aa","bb","cc"],["b","b","v"]];
var hash = {};
var result = [];
for(var i = 0, len = arr.length; i < len; i++){
if(!hash[arr[i]]){
result.push(arr[i]);
hash[arr[i]] = true;
}
}
alert(result);
[/code]