const lookup = {
alpha : 'Adams',
bravo : 'Boston',
charlie : 'Chicago',
delta : 'Denver',
echo : 'Easy',
foxtrot : 'Frank'
}
result = lookup[val];
im confused as to why i am able to do lookup[val]
but lookup.val
would not work here.
or something like
const testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
const playerNumber = 16;
const player = testObj[playerNumber];
testObj[playerNumber]
would work but testObj.playerNumber
would not. i initally assumed because 12,16,19 were int but even changing them to strings would be the same result where dot notation dont work but bracket will.
when storing an objects property into a var are we only allowed to use bracket? is so, how come if i was to do console.log(testObj.playerNumber)
would not work but console.log(testObj[playerNumber])
will?