Add new method contains to Array - Node.js Array

Node.js examples for Array:Add Element

Description

Add new method contains to Array

Demo Code


/**/*from   w  w w . ja va 2  s.  c  o m*/
 * Array.prototype.[method name] allows you to define/overwrite an objects method
 * returns true if element is in the array, and false otherwise
 */
Array.prototype.contains = function ( element ) {
    for (i in this) {
        if (this[i] === element) return true;
    }
    return false;
}

Related Tutorials