Reputation: 984
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,5];
console.log(arr);
output
[ 1, 2, 3, 4, 5 ]
desire output
[1,2,3,4,5]
Upvotes: 1
Views: 1930
Reputation: 23545
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 array
console.log(arr);
// Transform the arr into a string
console.log(JSON.stringify(arr));
Upvotes: 2