array.prototype.flatmap
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
call-bind | 1.0.7 | 21.6 kB | MIT | prod | |
define-properties | 1.2.1 | 5.08 kB | MIT | prod | |
es-abstract | 1.23.3 | 1 B | MIT | prod | |
es-shim-unscopables | 1.0.2 | 4.31 kB | MIT | prod |
Array.prototype.flatMap is a JavaScript npm package that provides an ES2019 spec-compliant shim, polyfill, or replacement for the Array.prototype.flatMap
method. This package works even in an ES3-supported environment. It is designed to flatten deeply nested arrays while also mapping each element to a new value, using a function that you provide.
To utilize array.prototype.flatmap, you need to install it via npm using command npm install --save array.prototype.flatmap
. Typical example of its usage involves first requiring it in your JavaScript file via var flatMap = require('array.prototype.flatmap')
.
Here's a sample usage:
var flatMap = require('array.prototype.flatmap');
var assert = require('assert');
var arr = [1, [2], [], 3];
var results = flatMap(arr, function (x, i) {
assert.equal(x, arr[i]);
return x;
});
assert.deepEqual(results, [1, 2, 3]);
In this example, we create a simple function that returns each element of the array and then flatMap returns a new array with the returned results, but any nested arrays are flattened.
The complete documentation for array.prototype.flatmap is located within the package's GitHub page and can be found at https://github.com/es-shims/Array.prototype.flatMap
, where you can find details about usage, test cases, and license information.