← Back to challenges

ES6: Destructuring Objects IX

JavaScriptHardlanguage_fundamentalsformattingobjectsarrays

Instructions

Given an array of user objects. If we just wanted to get the name of the third object in the array, one way could be to use an array method like:

let users = [
  { name: "John", email: "[email protected]" },
  { name: "Jason", email: "[email protected]" },
  { name: "Jeremy", email: "[email protected]" },
  { name: "Jacob", email: "[email protected]" }
]

let thirdUser = users.filter((e, i) => i === 2 )[0].name
console.log(thirdUser)  // "Jeremy"

However, you can combine array and Object destructuring to extract it more declaratively. Use array and object destructuring to extract the name from the third object in the users array and assign it to the variable thirdUser. Provide the solution inside the brackets only. Ignore the .toString() function (used for validation).

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Letters Shared between Two Words