ES

时间:2024-02-15 12:06:29

Object.fromEntries

从二维数组或 Map 中构造对象

const result = Object.fromEntries([
    ['name','尚硅谷'],
    ['xueke', 'Java,大数据,前端,云计算']
]);
const m = new Map();
m.set('name','ATGUIGU');
const result = Object.fromEntries(m);
const arr = Object.entries({
    name: "尚硅谷"
})
console.log(arr);

Object.entries()Object.fromEntries() 互为逆运算

// trim
let str = '   iloveyou   ';

console.log(str);
console.log(str.trimStart());
console.log(str.trimEnd());

flat 与 flatMap

用于展平数组,其接受一个参数,指明展平数组的维度

//flat 平
//将多维数组转化为低位数组
// const arr = [1,2,3,4,[5,6]];
const arr = [1, 2, 3, 4, [5, 6, [7, 8, 9]]];
//参数为深度 是一个数字
console.log(arr.flat(2));
//flatMap
const arr = [1, 2, 3, 4];
const result = arr.flatMap(item => [item * 10]);
console.log(result);

Symbol.prototype.description

获取创建 Symbol 时的字符串:

//创建 Symbol
let s = Symbol('尚硅谷');
console.log(s.description);