find

Type:Function
Status:stable
Since:1.0.0
Platform:jsnode
@blackbyte.sugar.shared.array

This function is a subset of the native “find”. It returns the:

  • index: the position in the array
  • value: the actual value at this position

Params

  1. ar*-Array

    The array in which to search for an item

  2. check*-Function

    The check function to test if the element is the searched one

Return

  1. -TFindResult|null

    An object containing the index and value of the finded item, or null if nothing found

Example

import { find } from '@blackbyte/sugar/array';
find(['hello','world'], (item: any) => item === 'world')
{
    index: 1,
    value: 'world'
}