unique
Remove duplicates from an array
159 bytes
since v12.1.0
Usage
Given an array of items — and optionally, a function to determine their identity — return a new array without any duplicates.
The function preserves the original order of items, keeping the first occurence and omitting duplicates.
import * as _ from 'radashi'
const fish = [ { name: 'Marlin', weight: 105, source: 'ocean', }, { name: 'Salmon', weight: 22, source: 'river', }, { name: 'Salmon', weight: 23, source: 'stream', },]
_.unique(fish, f => f.name)// [// { name: 'Marlin', weight: 105, source: 'ocean' },// { name: 'Salmon', weight: 22, source: 'river' }// ]