数组
[ li.size30x30, li.size60x30, li.size60x30, li.size30x30, li.size60x30,
li.size60x30, li.size60x30, li.size60x30, li.size30x30, 704 more… ]
期望结果数组[ li.size30x30, li.size60x30 ]
答案 0 :(得分:1)
var arrayEl = ['li.size30x30', 'li.size60x30', 'li.size60x30', 'li.size30x30', 'li.size60x30',
'li.size60x30', 'li.size60x30', 'li.size60x30', 'li.size30x30'
];
arrayEl = arrayEl.filter(function(v, i, arr) {
return i == arr.indexOf(v);
// checking array element already occured before the element using indexOf(), which returns index of first occurance
});
document.write(JSON.stringify(arrayEl));