What is the _.join() method in Lodash?
Overview
The _.join() method in Lodash converts all the values of an array into a string separated by the specified separator.
Syntax
_.join(array, separator)
_.join() syntax
Parameters
This method accepts the following parameters:
array: This is the array to be converted into a string.separator: This is the separator. Its default value is a comma (,).
Return value
This method returns a string of all the array values separated by the specified separator.
Example
Explanation
In the "HTML" tab:
- Line 5: We import the
lodashscript.
In the "JavaScript" tab:
- Line 2: We create the
infoarray and populate it with a few values. - Line 5: We create a
separatorand initialize it with_.
- Line 8: We use the
_.join()method to convert all the values of an array into a string. - Line 11: We print the
resultto the console.
Output
In the output, we see a string that contains all the values of the array separated by _.