VOOZH about

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

⇱ Lodash _.uniq() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.uniq() Method

Last Updated : 2 Sep, 2024

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

Syntax:

_.uniq(array);

Parameters:

  • array: This parameter holds an array to inspect.

Return Value:

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

Note: This code requires the Lodash library to be installed.

Example 1: In this example, we are getting an array having unique elements because of the lodash _.uniq() method.

Output:

[ 1, 2, 3, 4, 8, 6 ]

Example 2: In this example, we are getting an array having unique elements because of the lodash _.uniq() method.

Output:

[ 'a', 'b', 'c', 'e', 'd', 'g', 'i' ]

Example 3: In this example, we are getting an array having unique elements because of the lodash _.uniq() method.

Output:

[ 'apple', 'banana', 'chikoo', 'Elderberry', 'Damson', 'Date', 'guava', 'Damson Date' ]
Comment