Javascript Array contains(k)

Description

Javascript Array contains(k)


/**/*  www  .jav a 2 s  . c  om*/
 * Extend Array prototype with method to detect excistence of value in array
 * @param k
 * @returns {boolean}
 */
Array.prototype.contains = function (k) {
    'use strict';

    var p;

    for (p in this) {
        if (this.hasOwnProperty(p) && this[p] === k) {
            return true;
        }
    }

    return false;
};



PreviousNext

Related