JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1482
  • Score
    100M100P100Q119374F
  • License Apache-2.0

A collection of utilities for JavaScript arrays

Package Exports

  • @ultraq/array-utils
  • @ultraq/array-utils/array-utils.cjs.js
  • @ultraq/array-utils/array-utils.es.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ultraq/array-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

array-utils

Build Status codecov npm Bundlephobia minified size

A collection of array utilities, meant as a zero-dependency way of working with arrays.

Installation

Via npm:

npm install @ultraq/array-utils

API

flatten(array)

Flattens an array of arrays of infinite depth into a single-dimension array.

This is now natively in JavaScript as the flat method on an Array instance. Check MDN for which browsers have access to this feature. If you can't use flat, then this method will do the job 🙂

  • array: The array of arrays to flatten

range(start, end, step)

Creates an array of numbers from the starting value (inclusive) to the end (exclusive), with an optional step (the gap between values).

  • start: The value to start at, the first item in the returned array.
  • end: The value to end with, the last item in the returned array.
  • step: The increment/gap between values, defaults to 1.

remove(array, predicate)

Remove and return the first item from array that matches the predicate function.

  • array: The array to search and remove an item from
  • predicate: Function to test each item of the array with. If it returns a truthy value for the item, then that item is removed and returned.