Skip to content

Create a string from an array: `join()`

Create a string from an array: join()

If you want to generate a string, joining all the array elements, you can use the join() method. By default, the character is used as separator. If you want to use a specific separator you can call the join(’-’) method with the separator needed as the first argument.

const elements = ['kiwi', 'strawberry', 'lemon']
// expected output: "kiwi,strawberry,lemon"
// expected output: "kiwi-strawberry-lemon"