Let’s take a closer look at some of the ES2019 features:
-> Array.flat()
-> Array.flatMap()
-> Object.fromEntries()
-> String.trimStart()
-> String.trimEnd()
Array.flat():
Array.flat() will flatten the multi-dimensional arrays to the depth specified by the integer parameter in the function call.
Codepen: https://bit.ly/2U2Ps8W
Array.flatmap()
The flatMap() method is combination of http://Array.map() and Array.flat(). It first maps each element using map function and then tries to flatten the result using Array.flat(). Under the hood Array.flatMap() uses the Array.flat().
Object.fromEntries()
Object.fromEntries() simply allow us to transform a list of key-value pairs into an object.
Usecases:
- Object.fromEntries() comes in picture when working with a query string of a URL
Codepen: https://bit.ly/2U2Ps8W
String.trimStart() & String.trimEnd()
String.trimStart() method removes whitespace from the beginning of a string.
String.trimEnd() method removes whitespace from the end of a string.
Let’s look at the example below.
Codepen: https://bit.ly/2U2Ps8W