findAll

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

This function is a subset of the native “find” but it returns all the items that match the check function. It returns an array of objects, each containing 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. -TFindAllResult[]|null

    An array of objects containing the index and value of the found items, or null if nothing found

Example

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