Here's an example of what I was talking about, extending your object with a function that parses the string input and looks up the corresponding element.
A big caveat here is that I was lazy about handling of quotations, so you'll need to fiddle it a bit to handle single and double quotes. I haven't extensively tested, but I think it will return undefined when there's no match in the object.
var v1 = "['a']";
var v2 = "['b']['c']";
var obj = {
getByStr: function(str) {
var args = str.replace("['", '').replace(new RegExp("'\]" + '$'), '').split("']['");
var match = this[args.shift()];
while(match !== undefined && args.length > 0)
match = match[args.shift()];
return match;
},
a: 'a',
b: {
c: "['b']['c']"
}
};
document.write('v1 -- ' + obj.getByStr(v1) + '<br />');
document.write('v2 -- ' + obj.getByStr(v2) + '<br />');
If you think you might use it, but there's anything you don't understand in there, post a comment and I'll add some clarifications.