Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Asynchronous Programming with JavaScript What is Asynchronous Programming? Examples of Synchronous and Asynchronous Code

Scott Whitener
Scott Whitener
3,233 Points

Logging objects to the console

Maybe I missed something in an old vid but this syntax per 3:10 logs the objects to the console. I have no idea what this is:

data.map(p => console.log(p));

Is it some kind of loop? Was this .map function mentioned somewhere earlier?

1 Answer

Steven Parker
Steven Parker
220,853 Points

This is an intermediate-level course, and the "map" function was covered in the beginner-level course JavaScript Array Iteration Methods (and possibly some others also).

It generates a new array by applying the function argument to each element of the given array. How it is being used here seems a bit bizarre — I would have chosen "forEach" instead.

Anytime I run into something I don't recognize (or remember in detail), I just look it up on MDN. For example, here's the MDN page for map().

Scott Whitener
Scott Whitener
3,233 Points

Thanks Steven - I'll have to check out that array iteration course because its currently not included in the javascript full stack lineup.

And thanks for that MDN link - my searches kept finding the map object but the one you showed is under Arrays which makes total sense now.

Steven Parker
Steven Parker
220,853 Points

You might want to suggest adding that course to the full stack track to the Support folks!