Javascript String inArray(array);

Description

Javascript String inArray(array);


// Authors: Eric Manzi
/**//from  www  .  j a  v a2 s  .  c om
 * Returns true if string in array
 * @param array
 */
var inArray = function(array) {
    var str = this.toString();
    var filtered = array.filter(function(item) {
        return item===str;
    });
    return filtered.length > 0;
};

String.prototype.in = inArray;



PreviousNext

Related