Skip to content

Latest commit

 

History

History
90 lines (55 loc) · 2.57 KB

File metadata and controls

90 lines (55 loc) · 2.57 KB

Array Utilities

Description of the array utilities.

Import

import { array } from '@webalternatif/js-core'

API

inArray

src/array.js:24-51

Checks if a value exists in an array or an object

Parameters

  • value any the searched value
  • arr (Object | Array) the array
  • index number if provided, search from this index (optional, default 0)
  • strict boolean if true, search is done with strict equality (optional, default false)

Examples

inArray(2, [1, 2, 3]) => true
inArray({a: 1}, {a: 1, b: 2}) // => true
inArray(5, [1, 2, 3]) // => false

Returns boolean

indexOf

src/array.js:62-74

Returns the first index at which a given element can be found in an array or a string. or -1 if it is not present.

Parameters

  • arr (Array<any> | string) The array to search in
  • elt any The element to search for
  • from number? The index to start the search from. Can be negative. (optional, default 0)

Returns number The index of the element, or -1 if not found

lastIndexOf

src/array.js:85-97

Returns the last index at which a given element can be found in an array or a string. or -1 if it is not present.

Parameters

  • arr (Array<any> | string) The array to search in
  • elt any The element to search for
  • from number? The index to start the search from. Can be negative. (optional, default -1)

Returns number The index of the element, or -1 if not found