If we want to override the Examples section we would access sections[1]. This would fail if the Examples section later moved to a different position. It would be more reliable to retrieve a named section from a Map.
However, Arrays are ordered and Maps are not. It's easier to insert new sections at specific index positions within an Array than it is within a Map. To get the best of both worlds (named sections of Maps with the ordered nature of Arrays) we could keep the existing Array-based structure with an id or name property on each individual section, to make them addressable by name.
At the moment
sections
is an array. Say we have three sections:If we want to override the Examples section we would access
sections[1]
. This would fail if the Examples section later moved to a different position. It would be more reliable to retrieve a named section from aMap
.Define the sections:
Retrieve and override the examples:
However, Arrays are ordered and Maps are not. It's easier to insert new sections at specific index positions within an Array than it is within a Map. To get the best of both worlds (named sections of Maps with the ordered nature of Arrays) we could keep the existing Array-based structure with an
id
orname
property on each individual section, to make them addressable by name.