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