# ES10 ⭐️

# Object.fromEntries

可以说是entries的逆运算,把键值对转换成对象

const entries = new Map([
  ['foo', 'bar'],
  ['baz', 42]
]);
const obj = Object.fromEntries(entries);
console.log(obj);
// expected output: Object { foo: "bar", baz: 42 }

# trimStart与trimEnd

  • trimStart()清除字符串前面的空白字符
  • trimEnd()清除字符串后面的空白字符

# flat与flatMap

  • flat数组扁平化
var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]

var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]

var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]

//使用 Infinity,可展开任意深度的嵌套数组
var arr4 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]];
arr4.flat(Infinity);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

  • flatMap 方法与 map 方法和深度depth为1的 flat 几乎相同.
let arr = [1, 2, 3, 4]
let res1 = arr.map(x => [x * 2])
let res2 = arr.flatMap(x => [x * 2])
console.log(res1);//[ [ 2 ], [ 4 ], [ 6 ], [ 8 ] ]
console.log(res2);//[ 2, 4, 6, 8 ]

# Symbol.prototype.description

console.log(Symbol('desc').description);
// expected output: "desc"
lastUpdate: 5/13/2022, 6:22:38 PM