Chrome Extension

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
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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

Search Index Data (The code snippet can also be found with below search text)

_.join lodash
Was this helpful?
0 Comments
Join Devsheet Ask a Question