📌  相关文章
📜  javascript 数组删除重复项 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:24.386000             🧑  作者: Mango

代码示例6
function toUniqueArray(a){
    var newArr = [];
    for (var i = 0; i < a.length; i++) {
        if (newArr.indexOf(a[i]) === -1) {
            newArr.push(a[i]);
        }
    }
  return newArr;
}
var colors = ["red","red","green","green","green"];
var colorsUnique=toUniqueArray(colors); // ["red","green"]