11.14 Arrays of Objects

In the previous section, we kept things simple by sticking with one array, stuntGroup, whose elements were all strings. Be aware that JavaScript arrays are very flexible in that an array can have different types for its elements. So if you want to keep track of the cheerleaders’ heights, you could use the stuntGroup array to store string elements for the cheerleaders’ names and also number elements for the cheerleaders’ heights. Although that would be legal, there’s a better way to handle different types of values in an array—using an array of objects.

For an end-of-chapter exercise, you’ll be asked to implement an array of cheerleader objects where each cheerleader object holds a name and height, but in this section, ...

Get Web Programming with HTML5, CSS, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.