// Without optional chaining
let userAdmin = undefined;
if (payload.access && payload.access.admin && payload.access.admin[0]) {
userAdmin = payload.access.admin[0].user;
}// With optional chaining
const userAdmin = payload.access?.admin?[0]?.user;
const arr = ['a', 'b', ['c', 'd']];
const flattened = arr.flat();console.log(flattened);
// Result: ["a", "b", "c", "d"]
const myArray = [['one', 1], ['two', 2], ['three', 3]];
const obj = Object.fromEntries(myArray);console.log(obj);
// Result: {one: 1, two: 2, three: 3}

ES2021
String.prototype.replaceAll
String.prototype.replaceAll()
replaces all occurrences of a string with another string value.
// You can break the digits in any way
const BIGNUMBER = 1234_5678_9_0; // 1234567890// Even after the comma/period
const PI = 3.1415_9265_3589; // 3.141592653589// However, ending or beginning with an underscore will return an error!const BAD_PI = 3.14_15_; // SyntaxError
const NO_MILLION = _1_000_000; // ReferenceError
Comments
Post a Comment