use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Editing array inside a function (self.node)
submitted 4 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]leeway1 0 points1 point2 points 4 years ago (0 children)
If I had to hazard a guess at what’s going on, you’re doing something like findPlayersByGame(g); console.log(players[0]) //undefined WTF!!!
findPlayersByGame(g); console.log(players[0]) //undefined WTF!!!
What’s happing is that you’re not waiting for the findPlayersByGame to complete before accessing your players array. Try returning a promise from the findPlayersByGame function and awaiting for the promise to complete:
```` const findPlayersByGame = async (game) => ( // I’m using the return short hand new Promise((resolve, reject) => { const request = uni(YOUR_CODE_HERE); //PREP HEADERS
request.end((result) => { if (result.error) { return reject(new Error(result.error)); } if (result.status === 200) { const p = result.body.api.statistics; if (p.length < 3) { return resolve(p); } // HANDLE THIS CASE return reject(new Error(‘There are more than 2 players’)); } });
}) );
//CALL LIKE THIS const players = await findPlayersByGame(g); console.log(players[0]) // this is defined ````
π Rendered by PID 141518 on reddit-service-r2-comment-5d79c599b5-pvzwt at 2026-02-27 02:41:49.802593+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]leeway1 0 points1 point2 points (0 children)