Skip to main content
added array delcaration for completeness.
Source Link
bendewey
  • 40.4k
  • 13
  • 104
  • 126

"Extension methods in JavaScript" via the prototype property.

Array.prototype.contains = function(value) {  
    for (var i = 0; i < this.length; i++) {  
        if (this[i] == value) return true;  
    }  
    return false;  
}

This will add a contains method to all Array objects. You can call this method using this syntax stringArray.contains("foobar");

var stringArray = ["foo", "bar", "foobar"];
stringArray.contains("foobar");

"Extension methods in JavaScript" via the prototype property.

Array.prototype.contains = function(value) {  
    for (var i = 0; i < this.length; i++) {  
        if (this[i] == value) return true;  
    }  
    return false;  
}

This will add a contains method to all Array objects. You can call this method using this syntax stringArray.contains("foobar");

"Extension methods in JavaScript" via the prototype property.

Array.prototype.contains = function(value) {  
    for (var i = 0; i < this.length; i++) {  
        if (this[i] == value) return true;  
    }  
    return false;  
}

This will add a contains method to all Array objects. You can call this method using this syntax

var stringArray = ["foo", "bar", "foobar"];
stringArray.contains("foobar");
Post Made Community Wiki by CommunityBot
deleted 54 characters in body
Source Link
Eric Schoonover
  • 48.5k
  • 50
  • 161
  • 203

"Extension methods in JavaScript" via the prototype property.

Array.prototype.contains = function(value) { for (var i = 0; i < this.length; i++) { if (this[i] == value) return true; } return false; }

Array.prototype.contains = function(value) {  
    for (var i = 0; i < this.length; i++) {  
        if (this[i] == value) return true;  
    }  
    return false;  
}

This will add a contains method to all Array objects. You can call this method using this syntax stringArray.contains("foobar");

"Extension methods in JavaScript" via the prototype property.

Array.prototype.contains = function(value) { for (var i = 0; i < this.length; i++) { if (this[i] == value) return true; } return false; }

This will add a contains method to all Array objects.

"Extension methods in JavaScript" via the prototype property.

Array.prototype.contains = function(value) {  
    for (var i = 0; i < this.length; i++) {  
        if (this[i] == value) return true;  
    }  
    return false;  
}

This will add a contains method to all Array objects. You can call this method using this syntax stringArray.contains("foobar");

Source Link
Eric Schoonover
  • 48.5k
  • 50
  • 161
  • 203

"Extension methods in JavaScript" via the prototype property.

Array.prototype.contains = function(value) { for (var i = 0; i < this.length; i++) { if (this[i] == value) return true; } return false; }

This will add a contains method to all Array objects.