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

Console
Implementation of the _.join() method

Explanation

In the "HTML" tab:

  • Line 5: We import the lodash script.

In the "JavaScript" tab:

  • Line 2: We create the info array and populate it with a few values.
  • Line 5: We create a separator and 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 result to the console.

Output

In the output, we see a string that contains all the values of the array separated by _.

Free Resources