-9

Considering this API randomuser, how do I destructure the API to obtain the results property?

noetix
  • 4,773
  • 3
  • 26
  • 47
OdunayoO
  • 21
  • 2
  • 7

2 Answers2

1

{results : [{gender etc.}]} then you will only get the properties enumerated

Michael
  • 4,538
  • 5
  • 31
  • 58
0

Here's how you would destruct the results prop from that endpoint:

(async () => {
  const data = await fetch('https://randomuser.me/api/')

  const { results } = await data.json()

  console.log(results) // returns `results` array from object
})()
noetix
  • 4,773
  • 3
  • 26
  • 47