DEV Community

Jared Burnham
Jared Burnham

Posted on

ES 2019 fun stuff even though 2019 is already almost over

ecmascript has released some new functionality throughout 2019. I'm going to go over a few of the things that has been implemented in javascript
javascript implemented a flat() that flattens arrays


const a = [1,[2,[3,[4]]]]
a.flat() //=> [1,2,array(2)]
a.flat(3) //=> [1,2,3,4]
a.flat(Infinity)

pass infinity for unknown depth. will flatten into a single array

can turn array into objects. If you want an object with more that on key value pair the array must be formatted as [[k,v],[k,v],[k,v]] (that will give you and object with 3 key value pairs.) for single key value pair use [[k,v]] If the nested array only has one element it will only assign a key with value undefined. everything after the second element in the nested array will not be used


let objectWannaBe = new Map([[key1, value1], [key2, value2]])

Object.fromEntries(objectWannaBe) //=> { key1: value1, key2: value2 }

          import React from 'react';
          import logo from './logo.svg';
          import './App.css';

added more trim functionality

const a = " a "
const newA = a.trimStart() //=> "a "
newA.trimEnd() //=> "a"


function.toString() is a thing

you can use catch without passing it an argument

Top comments (0)