Nodejs Array Push If Not Exist pushIfNotExist(element, comparer)

Here you can find the source of pushIfNotExist(element, comparer)

Method Source Code

// adds an element to the array if it does not already exist using a comparer 
// function//from www.j  a v a 2s.c om
Array.prototype.pushIfNotExist = function(element, comparer) { 
    if (!this.inArray(comparer)) {
        this.push(element); 
        return true;
    }
    return false;
}; 


// find index of object in array given some property value
function arrayObjectIndexOf(myArray, property, searchTerm) {
    for(var i = 0, len = myArray.length; i < len; i++) {
        if (myArray[i][property] === searchTerm) return i;
    }
    return -1;
}

// find index of item in array
function arrayIndexOf(myArray, searchTerm) {
    for(var i = 0, len = myArray.length; i < len; i++) {
        if (myArray[i] === searchTerm) return i;
    }
    return -1;
}

Related

  1. pushIfNotExist(element, comparer)
    Array.prototype.pushIfNotExist = function(element, comparer) { 
        if (!this.inArray(comparer)) {
            this.push(element);
    };
    
  2. pushIfNotExist(element, comparer)
    Array.prototype.pushIfNotExist = function(element, comparer) { 
        if (!this.inArray(comparer)) {
            this.push(element);
    };
    
  3. pushIfNotExist(element, comparer)
    Array.prototype.pushIfNotExist = function(element, comparer) { 
        if (!this.inArray(comparer)) {
            this.push(element);
    }; 
    function arrayObjectIndexOf(myArray, property, searchTerm) {
        for(var i = 0, len = myArray.length; i < len; i++) {
            if (myArray[i][property] === searchTerm) return i;
        return -1;
    
  4. pushIfNotExist(item)
    Array.prototype.pushIfNotExist = function (item) {
        if (item == null)
            return;
        var exist = false;
        for (var i = 0; i < this.length; i++) {
            if (this[i] == item) {
                exist = true;
                break;
        if (!exist)
            this.push(item);
    };
    
  5. pushIfNotExist(item)
    Array.prototype.pushIfNotExist = function(item) {
      if (!this.inArray(item)) {
        this.push(item);
    };
    
  6. pushIfNotPresent(pValue)
    Array.prototype.pushIfNotPresent = function (pValue){
        var lArray = this || [];
        if (lArray.indexOf(pValue) == -1){
            lArray.push(pValue);
            return true;
        return false;