What is the _.concat() method in Lodash?

Overview

The _.concat() method in Lodash is used to create a new array by concatenating two or more arrays.

Syntax

_.concat(array, [values])

Parameters

This method accepts the following parameters:

  • array: The array to be concatenated.
  • [values]: The values to be concatenated.

Return value

This method returns a concatenated array.

Example

Let’s look at an example of the _.concat() method in the code snippet below:

Console

Explanation

In the HTML tab:

  • Line 5: We import the lodash script.

In the JavaScript tab:

  • Line 2: We create an array and initialize it with a some values.
  • Line 5: We create another array and initialize it with values.
  • Lines 8: We use the _.concat() method to concatenate both the arrays.
  • Lines 11: We print the output on the console.

Output

In the output, we see an array in which both the arrays are concatenated.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources