1.0.6 • Published 6 years ago

@kingjs/array.nested.for-each v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@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

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago