I think I don’ t understand why we need to access the value of a property for an object via variable in the following way:
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
var playerNumber = 16; // Change this Line
var player = testObj[playerNumber]; // Change this Line
When we could do it like this directly:
var player = testObj["16"];, for example.
In the lesson, it is said: " This can be very useful for iterating through an object’s properties or when accessing a lookup table."
But I don’t quite understand what it means. Could you give an easy example if possible?
My browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables/