Which indexOf function should I use?
<p>I've encountered this code in a codebase to add the indexOf function : </p>

<pre><code>if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length &gt;&gt;&gt; 0;

    var from = Number(arguments[1]) || 0;
    from = (from &lt; 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from &lt; 0)
      from += len;

    for (; from &lt; len; from++)
    {
      if (from in this &amp;&amp;
          this[from] === elt)
        return from;
    }
    return -1;
  };
}
</code></pre>

<p>This is a different implementation to the one recommended by Mozilla <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf" rel="nofollow">https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf</a> : </p>

<p>Code:</p>

<pre><code>   if (!Array.prototype.indexOf) {  
        Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {  
            "use strict";  
            if (this == null) {  
                throw new TypeError();  
            }  
            var t = Object(this);  
            var len = t.length &gt;&gt;&gt; 0;  
            if (len === 0) {  
                return -1;  
            }  
            var n = 0;  
            if (arguments.length &gt; 0) {  
                n = Number(arguments[1]);  
                if (n != n) { // shortcut for verifying if it's NaN  
                    n = 0;  
                } else if (n != 0 &amp;&amp; n != Infinity &amp;&amp; n != -Infinity) {  
                    n = (n &gt; 0 || -1) * Math.floor(Math.abs(n));  
                }  
            }  
            if (n &gt;= len) {  
                return -1;  
            }  
            var k = n &gt;= 0 ? n : Math.max(len - Math.abs(n), 0);  
            for (; k &lt; len; k++) {  
                if (k in t &amp;&amp; t[k] === searchElement) {  
                    return k;  
                }  
            }  
            return -1;  
        }  
    }  
</code></pre>

<p>Should I be using the Mozilla version instead or will version mentioned at beginning of question suffice ? Are there advantages of using one over the other ?</p>
