Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a space between each word in an array

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.

Example of how it could look:

    function printWords() {
      var array = ["Car", "Bus", "Motorcykle"];
      print(array.addSpaces());
    }
like image 952
Chris Avatar asked Oct 20 '17 19:10

Chris


1 Answers

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

array.join(' ');
like image 182
LW001 Avatar answered Nov 07 '22 07:11

LW001