<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[array - All your code are belong to us]]></title><description><![CDATA[Thoughts, stories and ideas on code and technology in general.<br>Blog title inspired by <a href="https://en.wikipedia.org/wiki/All_your_base_are_belong_to_us" target="_blank">this meme</a>]]></description><link>https://allurcode.com/</link><image><url>https://allurcode.com/favicon.png</url><title>array - All your code are belong to us</title><link>https://allurcode.com/</link></image><generator>Ghost 4.48</generator><lastBuildDate>Thu, 11 Jun 2026 09:22:46 GMT</lastBuildDate><atom:link href="https://allurcode.com/tag/array/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[JavaScript, return index of an element in array]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Recently I&#x2019;ve been working on a <a href="http://lookbook.monsoon-accessorize.co.uk/">project</a> with HTML5&apos;s <code>&lt;video&gt;</code> tag event handling and I needed to check if an element exists in the array. Quick googling resulted in neat native JavaScript method <code>Array.indexOf</code>. It returns the first index at which a given</p>]]></description><link>https://allurcode.com/javascript-return-index-of-an-element-in-array/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea12a</guid><category><![CDATA[array]]></category><category><![CDATA[bug]]></category><category><![CDATA[fix]]></category><category><![CDATA[ie]]></category><category><![CDATA[index]]></category><category><![CDATA[indexOf]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Mon, 30 Aug 2010 19:41:20 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>Recently I&#x2019;ve been working on a <a href="http://lookbook.monsoon-accessorize.co.uk/">project</a> with HTML5&apos;s <code>&lt;video&gt;</code> tag event handling and I needed to check if an element exists in the array. Quick googling resulted in neat native JavaScript method <code>Array.indexOf</code>. It returns the first index at which a given element can be found in an array, or -1 if it is not present. It all worked just fine in Firefox, Chrome and such.<br>
Why wasn&#x2019;t I surprised when my script behaved a bit weird in Internet Explorer. After many hours of &quot;fun&quot; with IE JavaScript debugger, I found that none of IE versions support the <code>Array.indexOf</code> method.</p>
<p>Thanks to <a href="http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/">this post</a> I was able to quickly fix it by adding below code to my script.</p>
<pre><code class="language-js">if(!Array.indexOf) {
  Array.prototype.indexOf = function(obj) {
    for(var i=0; i&lt;this.length; i++) {
      if(this[i]===obj) {
        return i;
      }
    }
    return -1;
  }
}
</code></pre>
<p>and the world was beautiful again.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item></channel></rss>