I'm trying to treat a JS object as a dictionary, and I want to use a pair of values (one literal value, one other object) as a single key, which I've been putting in array form, without success. The problem is that only the literal value is working to differentiate the keys, as the following snippet illustrates:
var dictionary = {};
var keyOne = { blah:1 };
var keyTwo = { blegh:2 };
var keyArrayOne = [keyOne, "label"];
var keyArrayTwo = [keyTwo, "label"];
dictionary[keyArrayOne] = "some data";
console.log(dictionary[keyArrayTwo]); //Console returns 'some data'
I know I can use an array in place of my dictionary object, and just iterate through and compare, but was hoping to take advantage of the quicker look-up.
For more info, I won't know anything about the object that constitutes the first element of the key (it can be anything), but the second part is always a string.
Is there any way to achieve what I'm after?