Javascript Array pushIfNotExist(element)

Description

Javascript Array pushIfNotExist(element)


// adds an element to the array if it does not already exist using a comparer 
// function/*from   w ww  . j  a  v a 2 s .  com*/
Array.prototype.pushIfNotExist = function (element) {
    if (this.indexOf(element)==-1) {
        this.push(element);
    }
};
String.prototype.padLeft = function (n,chr) {
    var res = this;
    while (n > res.length) {
        res = chr + res;
    }
    return res;
}



PreviousNext

Related