Skip to content Skip to sidebar Skip to footer

Javascript: Remove White Space Of Output Array In Browser Console

Is there any method to remove unnecessary spaces of output array. When I run the code there is space in between comma and integer and also integer and bracket. var arr = [1,2,3,4,

Solution 1:

console.log or console.log is a basic tool function which have very defined behavior that you can't change.

The only thing you can do is to use a trick. console.log handle differently the string and the arrays, so you can transform your array before to display it.

Moreover they didn't made it possible to influence the display because there is no purpose to it. What are you trying to achieve using console.log in your app?


console.log had been created in order to display debug messages, not to display data to regular users.

For example in node.js, in order to display data to your user in console, use of :

process.stdout.write(your_string_in_your_own_format);

const arr = [1,2,3,4,5];

// Basic arrayconsole.log(arr);

// Transform the arr into a stringconsole.log(JSON.stringify(arr));

Post a Comment for "Javascript: Remove White Space Of Output Array In Browser Console"