2

I call API on my react JS app :

result = fetch('http://localhost:5000/cities')

result.then(function(response) {
 console.log(response.json());
})

Then output log :

Promise
  __proto__ : Promise
  [[PromiseStatus]] : "resolved"
  [[PromiseValue]] : Array[5]
     0: Object
     1: Object
     2: Object
     3: Object
     4: Object
      length: 5
     __proto__: Array[0]

How do I fetch data on Array ?

I need get city name list

Khalid
  • 887
  • 2
  • 13
  • 26

1 Answers1

3

The line response.json() returns a promise that resolves to the parsed JSON.

You can simply write

result.then(function(response) {
  return response.json();
}).then(function (data) {
  console.log(data);
});
Aᴍɪʀ
  • 7,623
  • 3
  • 38
  • 52