Home > OS >  VSCode automatically formats console.log() output in terminal when logging an array that is longer t
VSCode automatically formats console.log() output in terminal when logging an array that is longer t

Time:01-18

I'm trying to log out an array in the terminal but it automatically formats it and adds a new line if the array is longer than 5 elements. How do I make it print normally in a single line.

Example code:

const someArray = [1,2,3,4,5,6,7]
console.log(someArray)

Result: Result of console.log

CodePudding user response:

It can be annoying sometimes, this is my solution to fix it when I need to print something line by line.

const someArray = [1, 2, 3, 4, 5, 6, 7, 8];
// The last parameter 4 is for indentation.
console.log(JSON.stringify(someArray, null, 4));

CodePudding user response:

This can solve your purpose.

const someArray = [1, 2, 3, 4, 5, 6, 7]
console.log(someArray.join(", "));
  •  Tags:  
  • Related