I have got a problem by searching JavaScript array by variable.
var category = $(this).data('ord');
Data category contains an array i.e: {"name":"John", "subsite":"example.com"}
I would like to search this array by variable called filter
that contains an filter.
I was trying to do var search = jQuery.inArray( filter, ord );
but this return undefined
I also was trying to do it in this way: var ord = $(this).data('ord').category;
this is not working too.
When i'm trying to do var category = JSON.parse($(this).data('ord'));
Console returns an error: SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
var order = JSON.parse($(this).data('ord'));
Arrow is pointing on JSON
pharse.
Can somebody explain to me how to do that correctly?
EDIT:
var ord = parseInt($(this).data('ord')[filter]);
Following code is looking for index by variable.