Member-only story
ES10 / ECMAScript2019
5. A Deep Dive into the Latest JavaScript Features — ES10
The JavaScript has been evolved a lot and one of the widely used language in the world. We are discussing about some core feature of ES10 / ECMAScript 2019 / ECMA2019, the iteration of the ECMAScript standard. Let’s talk about exciting features that can streamline your workflow and enhance your code.
In this article, we’ll delve into some of the key features introduced in ES10:
1. Array.prototype.flat
The flat() method creates a new array with all sub-array elements, concatenated into it recursively, up to the specified depth. If no depth is provided, it defaults to 1 level.
const nestedArray = [1, [2, [3, 4, [5]]]];const flatArray = nestedArray.flat(); // Default, a depth of 1 level
console.log(flatArray); // [1, 2, [3, 4, [5]]]const deeplyFlatArray = nestedArray.flat(2); // Using a depth of 2 level
console.log(deeplyFlatArray); // [1, 2, 3, 4, [5]]2. Array.prototype.flatMap
The flatMap() method first maps each element using a mapping function, then flattens the result into a new array. It is essentially a combination of map() and flat().









