0

I can recover my api but I cannot recover firstname in my object people, do you have a solution?

here my code for select l'object people :

console.log(data['people']);

and i want select firstname in my object people

enter image description here

2 Answers2

0

Your people object is an array so, to get the firstname value you need to either loop in this array (with foreach or map) and then use .firstname, or you can just specify an entry

so you can do :

data['people'][0].firstname

or

data['people'].forEach(element => {
    element.firstname
});
-1

can you loop the array by using map.

data['people'].map((item, index) => {


console.log(item.firstname)
})
blockgo
  • 44
  • 4
  • `.map()` has a very specific usage. If you are simply trying to loop, use a `.forEach()`. (Or just a regular for-loop.) – Ivar May 03 '21 at 07:51
  • can we use this for(var x = 0; data['people'].length > x; x++){ data['people'][x].firstname } – blockgo May 03 '21 at 08:07