Answers for "how to remove all the repeated cells in a js array"

5

javascript to remove duplicates from an array

uniqueArray = a.filter(function(item, pos) {
    return a.indexOf(item) == pos; 
})
Posted by: Guest on October-22-2020
4

javascript array remove duplicates

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"]
Posted by: Guest on July-23-2019

Code answers related to "how to remove all the repeated cells in a js array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language