Permalänk
Medlem

Promise result Javascript

Hur kommer jag enklast åt innehållet i PromiseResult om mitt promise ser ut så här när jag inspekterar det i webbläsaren.
Jag vill komma åt arrayen i position 1 i PromiseResult, hur gör jag det?

Promise {<fulfilled>: Array(4)}
__proto__: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Array(4)
0: "hello"
1: (10) ["Hello", "Hello Kitty", "Hello (Adele song)", "Hello, Dolly! (musical)", "Hello Venus", "Hello, Love, Goodbye", "Helloween", "Hello, Dolly! (film)", "Hello, My Twenties!", "Hello Kitty Online"]
2: (10) ["", "", "", "", "", "", "", "", "", ""]
3: (10) ["https://en.wikipedia.org/wiki/Hello", "https://en.wikipedia.org/wiki/Hello_Kitty", "https://en.wikipedia.org/wiki/Hello_(Adele_song)", "https://en.wikipedia.org/wiki/Hello,_Dolly!_(musical)", "https://en.wikipedia.org/wiki/Hello_Venus", "https://en.wikipedia.org/wiki/Hello,_Love,_Goodbye", "https://en.wikipedia.org/wiki/Helloween", "https://en.wikipedia.org/wiki/Hello,_Dolly!_(film)", "https://en.wikipedia.org/wiki/Hello,_My_Twenties!", "https://en.wikipedia.org/wiki/Hello_Kitty_Online"]
length: 4
__proto__: Array(0)

Permalänk
Medlem

methodThatReturnsPromise().then(result => { result.forEach(item => { console.log(item); } }

alternativt

var result = await methodThatReturnsPromise(); result.forEach(item => { console.log(item); }

Permalänk
Medlem
Skrivet av Ernesto:

methodThatReturnsPromise().then(result => { result.forEach(item => { console.log(item); } }

alternativt

var result = await methodThatReturnsPromise(); result.forEach(item => { console.log(item); }

Litet tillägg om du av någon anledning inte vill eller kan köra arrow functions:

methodThatReturnsPromise().then(function(result) { result.forEach(function(item) { console.log(item); } }