Sitemap
Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

ES10 / ECMAScript2019

5. A Deep Dive into the Latest JavaScript Features — ES10

3 min readFeb 15, 2024

--

Press enter or click to view image in full size

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().

--

--

✅ open src 🚀 🚀
✅ open src 🚀 🚀

Written by ✅ open src 🚀 🚀

1. Open source contributor, Architect at Jio Platform Ltd. and The Author of fe-pilot. https://github.com/opensrc0/fe-pilot/

Stackademic
Stackademic

Published in Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.