VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-union-method/

⇱ Lodash _.union() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.union() Method

Last Updated : 2 Sep, 2024

Lodash _.union() method is used to take n number of arrays and create an array of unique values in order, from all given arrays using SameValueZero for equality comparisons.

Syntax: 

_.union(*arrays);

Parameters:

  • arrays: This parameter holds arrays to inspect.

Return Value:

  • This method is used to return the new array of combined values.

Example 1: In this example, we are passing two different arrays into the _.union() method and printing the result in the console.

Output:

[20, 12, 8, 15, 6]

Example 2: In this example, we are passing three different arrays into the _.union() method and printing the result in the console. 

Output:

[1, 2, 3, 4, 5, 6, 7]
Comment