javascript

Lodash - Create a string from array elements join with some separator

To join all elements of an array with some seperator and create a string, you can use _.join() method of lodash.

const arr = ["This", "is", "Programming", "world"];

// Join using -
const str = _.join(arr, '-');
// => This-is-Programming-world

// Join using space
const str_2 = _.join(arr, ' ');
// => This is Programming world

Syntax

_.join(Array, Seperator=',')

Parameters description

Array: [Required] The input array that contains values that need to be joined together with some seperator.

Seperator: [Optional] The seperator value that will join the array elements. The default value of Seperator is ',' means if you do not pass its value, it will separate the array values with commas.

Example Demo

Was this helpful?