Codementor Events

Let’s take a closer look at some of the ES2019 features:

Published Jun 20, 2021
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
E4Bz25UVcAERfEI.jpeg

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

Object.fromEntries()
Object.fromEntries() simply allow us to transform a list of key-value pairs into an object.
Usecases:

  1. Object.fromEntries() comes in picture when working with a query string of a URL
    Codepen: https://bit.ly/2U2Ps8W
    E4Bz246VEAImOIO.jpeg

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
E4Bz241VgAASozT.jpeg

Discover and read more posts from Ramanjaneya K
get started
post commentsBe the first to share your opinion
Show more replies