user2301515
user2301515

Reputation: 5117

Getting a newsapi data

I try to use https://newsapi.org new api

fetch(new Request('https://newsapi.org/v2/top-headlines....')).then(function(response) {
    var json = response.json();
    console.log(json);//It gives 'Promise {<resolved>: {…}}'
    console.log(json.Promise//not work
    console.log(json.Promise['[[promiseValue]]']);//not work
});

How to get a json.Promise['']['[[promiseValue]]']? Thank you for responses

Upvotes: 0

Views: 1188

Answers (1)

Quentin
Quentin

Reputation: 944203

See the MDN guide to Using Fetch:

fetch('http://example.com/movies.json')
  .then(function(response) {
    return response.json();
  })
  .then(function(myJson) {
    console.log(myJson);
  });

response.json() gives you a promise.

You need a new then function to get the value out of it.

Upvotes: 5

Related Questions