Khalid Khalid - 1 year ago 112
Javascript Question

How to fetch data Array in Promise

I call API on my react JS app :

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

result.then(function(response) {

Then output log :

__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

Answer Source

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) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download