Here’s what I’m looking to do..
var dual = new Array;
dual=[voter,thisID];
var matrix = new Array;
matrix[dual]=voteint; //this works..
but I’d like to easily access values by either or both key (array) element:
matrix[*,thisID])=answer;
except wildcards don’t exist in this way, right?
one could do…
matrix[voter+'.'+thisID]=voteint;
and do regex matching around the ‘.’ but is there a better/easier/faster way?
The second assignment replaces the array originally assigned to dual, making the first assignment useless. It can be written:
but only if voter and dual have been declared or created as variables earlier.
As above, the first assignment to matrix is redundant.
It “works” by assigning a property to matrix that is
dual.toString(), so if you’d written:then
is equivalent to:
if voteint has been assigned a value earlier.
Not in that context, no.
If the
.was replaced by a comma, yes.It is considered bad practice to use an Array where an Object is indicated, so better to use an Object here.
Your only reasonable option is to iterate over the object’s properties using for..in to test each property name to find the one you want. Note that you should also include a hasOwnProperty test to exclude inherited enumerable properties.