Given is the following js command:
[].flat;
Executing it in a browser (chrome/firefox): returns function
Executing it with nodejs v10.13.0: returns undefined
Now I am wondering what other methods are not in the node RTE and where the documentation of global Objects like Array
is.
Seems to be the same with Array.prototype.flatMap
.
The JavaScript array prototype constructor is used to allow to add new methods and properties to the Array() object. If the method is constructed, then it will available for every array. When constructing a property, All arrays will be given the property, and its value, as default. Syntax: Array.prototype.name = value.
The flat() method creates a new array with the elements of the subarrays concatenated into it. The map() method creates a new array whose elements are the results of a mapping function. The flatMap() method is the combination of the map() method followed by the flat() method of depth 1.
You'll need node 11 or higher for Array.prototype.flat
. MDN is a great resource both for learning about Javascript and as a reference. You will find information about usage, browser compatibility, and even polyfills there.
As for Node.js support of ES6+, the best resource is node.green with a very detailed and up to date list of supported features by node version.
It doesn't seem to be supported in node.js at the moment. A quick ES6 way of flattening (depth 1) an array:
[[1, 2], [3, 4]].reduce((acc, val) => [ ...acc, ...val ], [])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With