0

I'm stuck on this. Please guide me on this Javascript code.

I'm trying to print the names of each month on a separate line. The code I'm using is given below.

const printArray = (arr) => {
console.log( arr.join( "<br>" ) );
};
const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
printArray( months );

Now, this should come up with printing each element of the array or name of each month in a separate line but it's printing each element next to each other in the console.

"Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec"

whereas I want each element to be printed in a separate line as given below,

Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec

Please, tell me why is that happening and also tell me the fix to it!

2
  • The console does not use HTML markup Commented Jan 31, 2022 at 3:23
  • 2
    Use \n instead of <br>. The console uses normal white space characters, not HTML. Commented Jan 31, 2022 at 3:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.