var myObj = {
test: 0,
other: 'none'
};
var readItem = 'test';
console.log(myObj.readItem);
How would I be able to hold, in a variable, the name of an item in an object and then use that variable to call the item? Thanks!
var myObj = {
test: 0,
other: 'none'
};
var readItem = 'test';
console.log(myObj.readItem);
How would I be able to hold, in a variable, the name of an item in an object and then use that variable to call the item? Thanks!
Can be looked up via the indexer:
myObj[readItem]
var myObj = {
test: 0,
other: 'none'
};
var readItem = 'test';
console.log(myObj[readItem]);
You can access the object property by following pattern
myObj[readItem];
var myObj = {
test: 0,
other: 'none'
};
var readItem = 'test';
console.log(myObj[readItem]);