JavaScript JavaScript Arrays Loop Through Arrays Array Methods

Are you logging the final string to the console?

Any idea what's bumming?

script.js
const planets = ['Earth','Mars','Saturn','Mecury','Jupiter','Venus','Uranus','Neptune'];

planets.join(', ');

console.log(planets);

2 Answers

Hi. In your code, you are still logging the planets array to the console. You did join the array members into a string with the .join() method; however, that doesn't affect the original array. That method will return a new string. So in order to print that to the console you could do either of the following:

const planets = ['Earth','Mars','Saturn','Mecury','Jupiter','Venus','Uranus','Neptune'];

// Storing the result as a variable to use later
planetsAsString = planets.join(', ');

console.log(planetsAsString );

or

const planets = ['Earth','Mars','Saturn','Mecury','Jupiter','Venus','Uranus','Neptune'];

// Directly printing the results of planets.join() to the console, without creating a new variable
console.log(planets.join(', '));

I would recommend opening the developer tools in your browser and manually executing every line of code in both of these example (line by line) so that you can see the difference and see how it works. Please let me know if that helps.

sure thks!