@kingjs/array.nested.for-each

Invokes a callback on leafs of a tree whose internal nodes are nested arrays and whose leafs are any non-array value.

Stats

StarsIssuesVersionUpdatedCreatedSize
@kingjs/array.nested.for-each
1.0.63 years ago3 years agoMinified + gzip package size for @kingjs/array.nested.for-each in KB

Readme

@kingjs/array.nested.for-each

Invokes a callback on leafs of a tree whose internal nodes are nested arrays and whose leafs are any non-array value.

Usage

Flatten nested arrays like this:

var forEach = require('@kingjs/array.nested.for-each');

var result = [];

forEach([
  'a', [
    'b', [
      'c'
    ], 'd'
  ], 'e'
], function(x) {
  result.push(x);
});

result;

result:

[ 'a', 'b', 'c', 'd', 'e' ]

API

declare function forEach(
  target: any | any[],
  callback: (x) => void
)

Parameters

  • target: An non-array leaf or an array of nested array nodes interspersed with non-array leafs.
  • callback: Callback to invoke for each non-array element.
    • x: Current non-array leaf.

      Install

      With npm installed, run
      $ npm install @kingjs/array.nested.for-each
      

      License

      MITAnalytics

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.