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 trial

JavaScript JavaScript Arrays Loop Through Arrays Array Methods

terry okey
terry okey
3,187 Points

Assigning a "joined" string to a new var?

I have extensive notes but no mention of how to join arrays and then console.log them? Need new variable?

terry okey
terry okey
3,187 Points

I have this code but it says it is not logging the new string to the console?

const planets = ['Earth','Mars','Saturn','Mecury','Jupiter','Venus','Uranus','Neptune']; planets.join(', ') ; console.log(planets);

terry okey
terry okey
3,187 Points

Even the Mozilla DN page has no info on how to access a newly joined string?

1 Answer

terry okey
terry okey
3,187 Points

Sorry I found the answer finally on MDN. i was not expecting to put the join method right inside the console statement. I am still thinking in one move at a time.

const planets = ['Earth','Mars','Saturn','Mecury','Jupiter','Venus','Uranus','Neptune']; console.log(planets.join(', '));

You can also

const planets = ['Earth','Mars','Saturn','Mecury','Jupiter','Venus','Uranus','Neptune'].join(', '); 
console.log(planets);