Lodash – Uniq By method

  • Post author:
  • Post category:Lodash
  • Post comments:2 Comments
Lodash - Uniq By method

Syntax Of Lodash Uniq By method

_.uniqBy(array, [iteratee=_.identity])

This Lodash Uniq By method is like _.uniq except that it accepts iteratee which is invoked for each element in an array to generate the criterion by which uniqueness is computed.

Arguments

  • array (Array) โˆ’ The array to inspect.
  • [iteratee=_.identity] (Function) โˆ’ The iteratee invoked per element.

Output

  • (Array) โˆ’ Returns the new duplicate free array.

Example

var _ = require('lodash');
var numbers = [1.1, 2.1, 2.3, 4.2]
var result = _.uniqBy(numbers, Math.floor);
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 1.1, 2.1, 4.2 ]

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply