I have the following variables:
var opday = [],
opcategory = [],
opbarrio = [];
Then I have elsewhere:
var myparent = $me.parent().attr('data-filter-group');
Supposing myparent returns “category”, how can I create an object from that string that references the variable opcategory??
For example:
var myarray = "op" + myparent;
So that I might use that object like so:
alert(myarray[2]);
Thanks!
You can address variables declared in global scope as:
However, this does not work if you stick it inside of the function:
Explicitly tying the scope vars to
thisworks though: