Javascript Array pushIfUnique(entryIn)

Description

Javascript Array pushIfUnique(entryIn)


Array.prototype.pushIfUnique = function(entryIn){
    var arr = this;
    var unique = true;
    arr.forEach(function(entry){
        if(entryIn === entry){
            unique = false;// ww  w . ja  v a 2s.c o m
        }
    });
    if(unique){
        arr.push(entryIn);
    }
};



PreviousNext

Related