Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

lodash
communitycreator

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

Shubham Singh Kshatriya

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

RELATED TAGS

lodash
communitycreator

CONTRIBUTOR

Shubham Singh Kshatriya

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring