JSFiddle - React, Tailwind, and code Playground

by squarefoo

JavaScript

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

alert(['a','b', 'c'].indexof2('a'));