-9

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

noetix
  • 4,533
  • 2
  • 25
  • 46
OdunayoO
  • 21
  • 2
  • 7

2 Answers2

1

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

Michael
  • 3,562
  • 4
  • 24
  • 52
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,533
  • 2
  • 25
  • 46