Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmohammed mayat
4,228 Pointstrouble putting object array into a variable
once you log external data to the console, how do you iterate and put object array into a variable so can you use it
i want to get the avg_signal put it in a variable so I can use it to change the position of the shape I created in html canvas https://lukenelson.co.uk/wifi-tracking/track.php?callback=eggs
2 Answers
Steven Parker
230,867 PointsIf you're retrieving this data in JSON format, the response should be an array. For example, you could log all the "avg_signal" values in the first element to the console this way:
for (var req of response[0].probe_requests)
console.log(req.avg_signal);
Yossi Haver
4,037 Pointsyou can use the eggs array, the array returning from the eggs function and run this
eggs.map(item => item.probe_requests)[0].reduce((result, currVal) => { result.push(currVal.avg_signal); return result; }, []);