UNPKG

@extra-array/flat-map.min

Version:

Flattens nested array, based on map function.

59 lines (42 loc) 1.75 kB
Flattens nested array, based on map function. [:package:](https://www.npmjs.com/package/@extra-array/flat-map) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/flat-map) [:vhs:](https://asciinema.org/a/332052) [:moon:](https://www.npmjs.com/package/@extra-array/flat-map.min) [:scroll:](https://unpkg.com/@extra-array/flat-map/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Alternatives: [flat], [flatMap]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array > This is browserified, minified version of [@extra-array/flat-map].<br> > It is exported as global variable **array_flatMap**.<br> > CDN: [unpkg], [jsDelivr]. [@extra-array/flat-map]: https://www.npmjs.com/package/@extra-array/flat-map [unpkg]: https://unpkg.com/@extra-array/flat-map.min [jsDelivr]: https://cdn.jsdelivr.net/npm/@extra-array/flat-map.min <br> ```javascript array.flatMap(x, [fm], [ft]); // x: an array // fm: map function (v, i, x) // ft: test function (v, i, x) ``` ```javascript const array = require("extra-array"); var x = [[1, 2], [3, [4, [5]]]]; array.flatMap(x); // [ 1, 2, 3, [ 4, [ 5 ] ] ] array.flatMap(x, v => array.flat(v, 1)); // [ 1, 2, 3, 4, [ 5 ] ] array.flatMap(x, v => array.flat(v)); // [ 1, 2, 3, 4, 5 ] ``` <br> <br> ## References - [Array.prototype.flatMap: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) - [_.flatten: lodash](https://lodash.com/docs/#flatten) [flat]: https://github.com/nodef/extra-array/wiki/flat [flatMap]: https://github.com/nodef/extra-array/wiki/flatMap