Check if variable is within an associative array in jQuery
<p>I have this code that loops through a HTML structure and builds an array based on its data attributes. I want to execute a conditional statement within a <code>foreach</code> loop and want to check if my <code>count</code> variable is within the array. I looked at <code>inArray()</code> but I'm not sure it works with <code>associative arrays</code>?</p>

<p>Here is the HTML</p>

<pre><code>&lt;div class="dfp" data-adposition="&lt;?php echo $dfpPos; ?&gt;" data-dfpcode='&lt;?php echo $dfpCode; ?&gt;'&gt;
&lt;/div&gt;

&lt;div class="dfp" data-adposition="&lt;?php echo $dfpHalfPos; ?&gt;"  data-dfpcode='&lt;?php echo $dfpHalfCode; ?&gt;'&gt;
&lt;/div&gt;
</code></pre>

<p>Here is the JS that builds the array.</p>

<pre><code>var dfpObj = { "adverts" : [] }; 

$(".dfp").each(function(){  // PROCESS DFPS
    var code = $(this).data("dfpcode");
    var position = $(this).data("adposition");
    var dfp = {
        "code": code,
        "position": position
    }
    dfpObj.adverts.push(dfp);
});
</code></pre>

<p>And my IF statement. </p>

<pre><code>if($.inArray(count, dfpObj.adverts) !== -1) {
    var dfp = $('.dfp[data-adposition=' + count + ']');
    var dfpcode = $(dfp).data("dfpcode"); 
    var dfppos = $(dfp).data("adposition");
    myfunction(dfpcode, dfppos);
}
// count is within a foreach loop so at the end of the loop is $count++
</code></pre>