Search array by variable in jQuery
<p>I have got a problem by searching JavaScript array by variable.</p>

<pre><code>var category = $(this).data('ord');
</code></pre>

<p>Data category contains an array i.e: <code>{"name":"John", "subsite":"example.com"}</code></p>

<p>I would like to search this array by variable called <code>filter</code> that contains an filter.</p>

<p>I was trying to do <code>var search = jQuery.inArray( filter, ord );</code> but this return <code>undefined</code> </p>

<p>I also was trying to do it in this way: <code>var ord = $(this).data('ord').category;</code> this is not working too.</p>

<p>When i'm trying to do <code>var category = JSON.parse($(this).data('ord'));</code></p>

<p>Console returns an error: <code>SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
var order = JSON.parse($(this).data('ord'));</code></p>

<p>Arrow is pointing on <code>JSON</code> pharse.</p>

<p>Can somebody explain to me how to do that correctly? </p>

<p>EDIT:</p>

<p><code>var ord = parseInt($(this).data('ord')[filter]);</code></p>

<p>Following code is looking for index by variable.</p>