Member-only story
ES6+ Series
ECMAScript 2019 introduced a few new built-in functions: flat and flatMap on Array.prototype for flattening arrays, trimStart and trimEnd on String.prototype, and Object.fromEntries for directly turning the return value of Object.entries into a new Object
trimStart() and trimEnd()
Return a new string with removed white space from the start of the original string and end of the original string.
const one = " hello and let's ";
const two = "begin ES6+ series. ";
console.log( one.trimStart() + two.trimEnd())
// "hello and let's begin ES6+ series ."Array.flat()
Array.flat() returns a new array with any sub-array(s) flattened. A call to Array.flat() without any arguments will only flatten one-level deep. An optional depth argument can be provided or it can just be called consecutively.
let arr = [1, 2, 3, [4, 5, 6, [7, 8, 9, [10, 11, 12]]]];
arr.flat(); // [1, 2, 3, 4, 5, 6, Array(4)];
arr.flat().flat(); // [1, 2, 3, 4, 5, 6, 7, 8, 9, Array(3)];
arr.flat(3); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
// Or, if you're not sure about the depth of the array:
arr.flat(Infinity); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]








