简体   繁体   English

Javascript:在浏览器控制台中删除输出数组的空白

[英]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,5];
console.log(arr);

output 产量

[ 1, 2, 3, 4, 5 ]

desire output 欲望输出

[1,2,3,4,5]

console.log or console.log is a basic tool function which have very defined behavior that you can't change. console.logconsole.log是基本的工具功能,具有非常明确的行为,您无法更改。

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. console.log处理stringarrays不同,因此您可以在显示数组之前对其进行转换。

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实现什么?


console.log had been created in order to display debug messages, not to display data to regular users. 创建console.log是为了显示调试消息,而不是向常规用户显示数据。

For example in node.js , in order to display data to your user in console, use of : 例如在node.js ,为了在控制台中向用户显示数据,请使用:

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)); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM