It is possible to destructure
objects and arrays that are nested
inside an object or an array.
In the example given above,
we destructure not just the user object,
but also the nested contactInfo object
to obtain the value of
the property user.contactInfo.email
and
store it in a variable email.
In the example given above,
we destructure not just the user object,
but also the emails property
to obtain the first element of user.emails
and
store it in a variable primaryEmail.
In the example given above,
we destructured the teamMembers array,
and store the values of the name properties
of both the elements of the array
and
in the variables
firstPersonName and secondPersonName,
respectively.
In the example given above,
we destructured the numbers array,
as well as the
two arrays nested inside numbers.
The first elements of both the nested arrays
are stored in the variables
oddNumber and evenNumber,
respectively.