App Lab Documentation

[list].join

Category:Variables

Sometimes we want to put all of the items in our lists together. join allows us to do this and to choose what we want in between each of the items. The separator we choose will be placed between every single item in the resulting string.

Examples

Example: Simple Join

Join a list of strings with the word "and"

var colors = ["red","orange","yellow","green","blue"];
console.log("My favorite colors are " + colors.join(" and "));

Example: Multiline-String

Join a string so that each element prints on another line.

var colors = ["red","orange","yellow","green","blue"];
console.log("My favorite colors are:\n" + colors.join(" \n "));

Syntax

[list].join("separator")

Parameters

NameTypeRequired?Description
listvariable name

The variable name of the list (array) you want to join

separatorstring

The string to use to join the list (array). If none is given a comma will be used

Returns

The list (array) as a single string, connected by the given separator.

Tips

  • If you use the newline character "\n" as your separator you can create a list in which each element prints on a different line.

Found a bug in the documentation? Let us know at support@code.org.