![]() |
VOOZH | about |
Lodash _.uniqBy method is similar to _.uniq except that it accepts iteratee which is invoked for each element in an array to generate the criterion by which uniqueness is computed. The order of result values is determined by the order they occur in the array.
_.uniqBy([array], [iteratee = _.identity]) Example 1: In this example, we use Lodash _.uniqBy() method to remove the duplicate values from the array ensuring only unique values are left in the array.
Output:
[2.4, 1.6 ]Example 2: In this example, we use Lodash _.uniqBy() method to remove the duplicate values of x based on properties.
Output:
[ { 'x': 2 }, { 'x': 1 } ] Example 3: In this example, we remove duplicate strings from an array using Lodash’s _.uniqBy() method.
Output:
[ 'aee', 'bee', 'cee', 'eee', 'dee', 'gee' ]