we will look at what is included in the latest version of ECMAScript : ES2019

 Array.prototype.flat() / Array.prototype.flatMap() 

Array.prototype.flat() will flatten the array recursively up to the depth that we specify. If no depth argument is specified, 1 is the default value. We can use Infinity to flatten all nested arrays.

 const letters = ['a', 'b', ['c', 'd', ['e', 'f']]];

 // default depth of 1


// ['a', 'b', 'c', 'd', ['e', 'f']] 

// depth of 2 letters.flat(2); 

// ['a', 'b', 'c', 'd', 'e', 'f'] 

// which is the same as executing flat with depth of 
   1 twice letters.flat().flat(); 

// ['a', 'b', 'c', 'd', 'e', 'f'] 

// Flattens recursively until the array contains no nested arrays letters.flat(Infinity)

 // ['a', 'b', 'c', 'd', 'e', 'f'] 

Array.prototype.flatMap() is identical to the previous one with regards to the way it handles the depth argument,

but instead of simply flattening an array, with flatMap() we can also map over it and return the result in the new array.

 let greeting = ["Greetings from", " ", "Vietnam"]; 

// let's first try using a normal `map()` function

 greeting.map(x => x.split(" ")); 

// ["Greetings", "from"] 

// ["", ""] 

// ["Vietnam"]

 greeting.flatMap(x => x.split(" ")) 

// ["Greetings", "from", "", "", "Vietnam"] 

As you can see, if we use .map() we will get a multi level array, which is a problem that we can solve by using .flatMap() . This will also flatten our array .


Object.fromEntries() transforms a list of key-value pairs into an object.

 const keyValueArray = [ 

['key1', 'value1'],

 ['key2', 'value2'] ]

 const obj = Object.fromEntries(keyValueArray) 

// {key1: "value1", key2: "value2"} 

We can pass any iterable as argument of Object.fromEntries() , whether it’s an Array , a Map or other objects implementing the iterable protocol. You can read more about the iterable protocol. here.

 String.prototype.trimStart() / .trimEnd() 

String.prototype.trimStart() removes white space from the beginning of a string while String.prototype.trimEnd() removes them from the end.

 let str = " this string has a lot of whitespace "; 

str.length; // 42 str = str.trimStart(); 

// "this string has a lot of whitespace " str.length;

 // 38 str = str.trimEnd(); 

// "this string has a lot of whitespace" str.length; 

// 35 

We can also use .trimLeft() as an alias of .trimStart() and .trimRight() as an alias of .trimEnd()

what is ECMAScript in JavaScript

ECMAScript is object-oriented and conceived as a core language to which may be added the objects of any specific domain or context like the thought of a “document.” (for example, the planet Wide Web Consortium’s Document Object Model).

ECMAScript along side the Document Object Model corresponds closely to the present implementations of JavaScript and JScript.

Although likely to be used mainly as a typical script language for the planet Wide Web, ECMAScript could even be used for any scripted application.

ECMAScript may be a standard script language, developed with the cooperation of Netscape and Microsoft and mainly derived from Netscape’s JavaScript, the widely-used scripting language that’s utilized in sites to affect how they look or behave for the user.

Microsoft states that its latest version of JScript is that the first implementation of the ECMAScript standard.

The official standard, ECMA-262, was developed under the auspices of the ecu Computer Manufacturers Association (ECMA).Having the ECMAScript standard will help ensure more consistency between Netscape, Microsoft, and the other Web script implementations.

If you like this post, don’t forget to share 🙂

This article is written by our awesome writer
Comments to: What’s new in ES2019 In JavaScript

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories


Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page


Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
    Strength indicator
    Log In | Lost Password