Javascript 如何用空格分隔数字数组?

Javascript 如何用空格分隔数字数组?,javascript,Javascript,假设我的数组是: const array = [20, 30, 21, 15, 80]; 例如,如果我想记录console.log,它将显示以下内容: 20,30,21,15,80 但我希望输出是 20 30 21 15 80 在console.log中 如何使用空格将其分开?我试过使用.split和其他东西,但都没用。提前谢谢 您可以使用.join() const数组=[20,30,21,15,80]; console.log(array.join(“”))要显示实际的数字(而不是字

假设我的数组是:

const array = [20, 30, 21, 15, 80];
例如,如果我想记录console.log,它将显示以下内容:

20,30,21,15,80 
但我希望输出是

20 30 21 15 80
在console.log中

如何使用空格将其分开?我试过使用.split和其他东西,但都没用。提前谢谢

您可以使用
.join()

const数组=[20,30,21,15,80];

console.log(array.join(“”))
要显示实际的数字(而不是字符串),您可以将数字从
array
分散到对
console.log
的调用中。由于console.log可以接受多个参数,因此它将在同一行中打印每个参数:
const数组=[20,30,21,15,80];
log(…数组)