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?
Similar Posts
- Lodash - Get index of array item based on some condition
- Remove new line separator from start and end positions of string in Javascript
- Join two arrays and remove duplicate elements using Javascript
- Remove first n elements from an array using Lodash
- Remove last n elements from an array using Lodash
- Lodash - Get all elements of array except the last one
- Test every item of array against some condition in javascript