如何在数组中每个单词之间打印空格 [英] How to print a space between each word in an array

查看:84
本文介绍了如何在数组中每个单词之间打印空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我记得在w3school上看到了一个函数,您可以在其中打印出数组的所有单词并在它们之间添加一个空格,但是无论我用多少Google谷歌我都找不到它。

I remember seeing a function on w3school where you can print out all the words of an array and add a space between them, But no matter how much I google I can't find it.

它的外观示例:

function printWords() {
  var array = ["Car", "Bus", "Motorcykle"];
  print(array.addSpaces());
}

预先感谢

推荐答案

使用 Array.prototype.join() 。您可以根据情况指定在值之间插入一个字符:

Use Array.prototype.join(). You can specify a character to put between the values, in your case:

array.join(' ');

这篇关于如何在数组中每个单词之间打印空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆