I'm trying to have a variable (plain text) used to reference another variable (Object) and then call on it to get information from the referenced variable (Object). In concrete:
var bar1 = {
p: 1,
v: 0.1,
sn: 1509475095
};
var bar2 = {
p: 2,
v: 0.2,
sn: 1509475095
};
foo = 'bar1';
console.log(bar1.p); // Prints 1
console.log(foo); // Prints 'bar1'
console.log(foo.p); // Want this to somehow print 1
Any ideas? I think this is related with the fact that foo
in my example is a String... but not sure how to manipulate the String to be able to get the reference.
Thanks in advance!