ES2019 features
What is new in ES2019 ( > Chrome 72)
Array flat
Create new array with all subArray elements
const arrayTest = [1,2, [3, 4, [4, 6, [7, 8 ]]]
Flat level 1
arrayTest.flat() //[ 1, 2, 3, 4, [ 4, 6 ] ]
Flat level 2
arrayTest.flat().flat() //[ 1, 2, 3, 4, 4, 6, [7, 8]]
Flat infinity
arrayTest.flat(infinity) //[ 1, 2, 3, 4, 4, 6 , 7, 8]
Array Flat Map
Map each element of array an then flattens the result into new array
const arrayTest = [1, 2, 3, 4]
maps and flat
const result = arrayTest.map(x => [x, x * 2]);
// [ [ 1, 2 ], [ 2, 4 ], [ 3, 6 ], [ 4, 8 ] ]
Object form Entries
create object from array entries
const arrayTest = [
['test1', 1],
['test2', 2],
['test3', 3]
]
Object entries
const result = Object.fromEntries(arrayTest)
//{ "test1": 1, "test2": 2, "test3": 3 }
Strim Start & Strim End
start/end remove space form the beginning/end
const stringToTrim = ' test ';
let result = stringToTrim.trimStart();
result = result.trimEnd()
//'test'
Optional catch binding
The error argument in the catch block is optional, Avoid creating unused binding
before
try {
} catch (error) {
....
}
after
try {
} catch {
....
}
See more ES10 features here