JS Standard LibraryPlaygroundPlayground
GitHubGitHub (opens in a new tab)
  • Introduction
    • arrIns
    • arrReplace
    • arrRm
    • bounds
    • chunk
    • compact
    • countBy
    • diff
    • drop
    • groupBy
    • intersection
    • intersperse
    • max
    • min
    • move
    • range
    • reverse
    • shuffle
    • sort
    • sortBy
    • swap
    • symDiff
    • take
    • union
    • uniq
    • isEmpty
    • isEql
    • isEqlArr
    • isNil
    • isShallowEql
    • aCompose
    • aComposeFn
    • aFilter
    • aForEach
    • aMap
    • aPipe
    • aPipeFn
    • aResolvers
    • hexToRGB
    • rgbToHex
    • compose
    • composeFn
    • noop
    • pipe
    • pipeFn
    • sleep
    • avg
    • clamp
    • divMod
    • isDisjointFrom
    • isEven
    • isOdd
    • isSubsetOf
    • isSupersetOf
    • mean
    • median
    • mode
    • percentage
    • percentageOf
    • prod
    • sum
    • isNegZero
    • isZero
    • toNum
    • clone
    • fromPath
    • get
    • has
    • merge
    • mergeAll
    • omit
    • pick
    • set
    • shallowMerge
    • shallowMergeAll
    • size
    • toPath
    • toSet
    • toUnset
    • unset
    • camelCase
    • capitalize
    • insertAt
    • isEmail
    • pascalCase
    • replaceAt
    • strReplace
    • isArr
    • isArrBuf
    • isAsyFn
    • isBigInt
    • isBlob
    • isBool
    • isDataView
    • isDate
    • isDef
    • isErr
    • isFn
    • isGenFn
    • isInfinity
    • isJSON
    • isMap
    • isNull
    • isNum
    • isObj
    • isPureObj
    • isRegEx
    • isSet
    • isStr
    • isSym
    • isTypedArr
    • isUndef
    • isWkMap
    • isWkRef
    • isWkSet

On This Page

  • Syntax
  • Examples
  • Try
Question? Give us feedback → (opens in a new tab)
Array
uniq

Creates a unique array by removing all duplicate values from the given array.

It uses isEql for deep comparison of values.

Syntax

import { uniq } from '@opentf/std';
 
uniq<T>(
  arr: T[] = [],
  by?: (val: T) => unknown
): Partial<T[]>

Examples

const arr = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5];
uniq(arr) //=> [1, 2, 3, 4, 5]
 
const arr = [2.1, 1.2, 2.3];
uniq(a, Math.floor) //=> [2.1, 1.2]

Try

unionisEmpty

MIT 2024 © Open Tech Foundation.