Javascript - Accessing Nested Data
Code Life
By Pierre Marsaa
Data Within Data
Imagine representing a full trainer profile: the trainer is an object with a team array, where each Codémon is an object with its own moves array! Deeply nested data looks complex at first glance, but reading it follows one simple rule:
↗️
Loading editor...
↶
↷
Always read the chain from left to right, one step at a time:
1.
trainer → the trainer object
2.
.team → its array of Codémon
3.
[0] → the first Codémon object (Aquachu)
4.
.moves → Aquachu's array of moves
5.
[1] → the second move ("Wave")
Verify