IndexOf method for Javascript

With the snippet below you can use the IndexOf method for Javascript.

Sample JS

Array.prototype.IndexOf = Array.prototype.IndexOf || function (element) {
    for (var i=0; i < this.length; i++) {
        if(this[i] === element) return i;
    }
    return -1;
};

Please Share us:
Please rate this snippet

2 thoughts on “IndexOf method for Javascript

Leave a Reply