ChApter 1 ■ JAvASCrIpt You Need to KNow
Andrew
Monica
Catie
Which approach you use can often be a matter of preference, but associative array syntax has some nifty benefits.
For example, you can use a variable name inside the brackets, which makes for some very handy dynamic behavior.
Listing 1-19 provides a quick example of this.
Listing 1-19. Associative Array
<!DOCTYPE html>
The important part of Listing 1-18 is where we update the firstName property using the previously declared
propertyName variable. Using dot syntax, you cannot do this. The output is as follows:
Catie
Christopher
■ Note Be careful when using associative array syntax. If you make a typo and write, say, ["firstNme"] instead of
["firstName"], you will actually create on the object a new property called firstNme.