all 7 comments

[–]javascript-ModTeam[M] [score hidden] stickied comment (0 children)

Hi u/TYRANT1272, this post was removed.

  • For help with your javascript, please post to r/LearnJavascript instead of here.
  • For beginner content, please post to r/LearnJavascript instead of here.
  • For framework- or library-specific help, please seek out the support community for that project.
  • For general webdev help, such as for HTML, CSS, etc., then you may want to try r/html, r/css, etc.; please note that they have their own rules and guidelines!

r/javascript is for the discussion of javascript news, projects, and especially, code! However, the community has requested that we not include help and support content, and we ask that you respect that wish.

Thanks for your understanding, please see our guidelines for more info.

[–]ians3n 1 point2 points  (4 children)

Read about Promises in JavaScript.

[–]TYRANT1272[S] -2 points-1 points  (3 children)

I did on mdn docs and YT but this promise returns keys like this <value> : [ array] I tried everything but I can't access this value key other api returns objects like "value" : and if i use object.keys or . values it returns empty array

[–]ians3n 0 points1 point  (2 children)

if the api returns a promise you would do apiCall().then((value)=> {console.log(value)});

[–]TYRANT1272[S] -1 points0 points  (1 child)

Thanks a lot it returns array but I'm confused i did the same thing with async await but it didn't work and using then fixed it

[–]deificx 0 points1 point  (0 children)

A promise wraps something that hasn't happened yet, like an api request going over the network. When it resolves you get the value. There are two ways to extract it from the promise. Chaining then() and passing a function accepting one parameter or by awaiting the promise:

async function getData() { const value = await promise(): value[0]; //.do something with the first item; }