0
let url = 'api url';

const players = [];
fetch(url)
.then(response => response.json())
 .then(data => players.push(data.included));

console.log(players);

I am using an api to view players on a server. My output:

https://imgshare.io/image/NyvUN5

I want to display all the name value of all current players. the number of objects in this array can be different at any time.

Justus
  • 1

2 Answers2

0

Loop through the players array and then access the properties of each player:

for (var player in players) {
    console.log(player.attributes.name);
}
Andrew Arthur
  • 1,563
  • 2
  • 11
  • 17
0
let url = 'api url';

const players = [];
fetch(url)
.then(response => response.json())
.then(data => players = data.map(v=>v.attributes.name));

I can fail because imgshare instead copypast json.