JavaScript 中的数组的去重
数组去重
方法1:利用对象属性不能重复
var arr = [1, 1, 1, 2, 2, 2, 3, 3, 3, "a", "a", "b", 1, 2, 3, 0, 0]; var obj = {}, arr2 = []; for (var i = 0; i < arr.length; i++) { if (!obj.hasOwnProperty(arr[i])) { obj[arr[i]] = arr[i]; arr2.push(arr[i]); } } console.log(arr2);