If I have an array and an object is it possible to use the array values as field name to get the object field value?
Like this:
var x = ['foo', 'bar'],
y = {
foo: 'foo,foo',
bar: 'bar,bar'
}
for (var i = 0, l = x.length; i < l; i++) {
console.log(y.x[i]);
// Uncaught TypeError: Cannot read property '0' of undefined
}
Except, this doesn't work.
Update
what if one of the object fields is a method like :
y = {
foo: 'foo,foo',
bar: function () {
alert('');
}
}