Related Articles

Related Articles

Lodash _.union() Method
  • Last Updated : 01 Sep, 2020

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

Syntax: 

_.union(*arrays)

Parameters: This method accepts a single parameter as mentioned above and described below:

  • arrays: This parameter holds arrays to inspect.

Return Value: This method is used to return the new array of combined values.

Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.



Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash");  
  
// Use of _.union() method 
let gfg = _.union([20, 12], [8, 15, 6]); 
        
// Printing the output  
console.log(gfg)

chevron_right


Output:

[20, 12, 8, 15, 6]

Example 2: 

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash"); 
  
// Use of _.union() method 
let gfg = _.union([1, 2, 3],
                  [3, 4, 5], 
                  [6, 2, 7]); 
        
// Printing the output  
console.log(gfg)

chevron_right


Output:

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

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :