← All languages
Swift function of the day
Random

Array.joined

Concatenate the elements of a sequence of sequences.

Description

The joined method concatenates the elements of a sequence of sequences into a single sequence. When called on an array of strings, joined(separator:) combines them into a single string with the given separator between each element.

The no-argument version joined() flattens nested sequences without a separator. The separator version is most commonly used with arrays of strings.

joined is the Swift equivalent of join in other languages like Python or JavaScript.

Arguments

NameDescriptionOptional
separator A string to insert between each element. Defaults to empty. Yes

Example

let words = ["Hello", "World"]
let sentence = words.joined(separator: " ")
print(sentence)  // "Hello World"

let csv = ["a", "b", "c"].joined(separator: ",")
print(csv)  // "a,b,c"

Reference