📌  相关文章
📜  javascript 获取数组的唯一项 - Javascript 代码示例

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

代码示例1
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"]