0
点赞
收藏
分享

微信扫一扫

ES6:Map()与WeakMap()

艾晓雪 04-04 23:00 阅读 2

1.展开可迭代对象(简单理解为数组和伪数组),如数组、 NodeList 、arguments。
可以通过展开运算符把一个伪数组转换为数组

const a = [...document.body.children];
console.log(a);
console.log(Array.isArray(a));

在这里插入图片描述
2.实现数组的浅拷贝

const a = [1,2,3];
const b = [...a];
console.log(b);

在这里插入图片描述
3.实现对象的浅拷贝和对象混入(对象属性的覆盖,后边的覆盖前边的)

const a={'a': 1, 'b': 2};
const b = {'b': 3, 'c': 1};
const c = {...a, ...b};
const d = {...a};
console.log(c);
console.log(d);

在这里插入图片描述
4.可以把一个数组展开成一个对象,对象的key就是数组的下标
在这里插入图片描述

举报

相关推荐

0 条评论