Set与Map

时间:2020-05-12 11:38:48   收藏:0   阅读:50

Ecmascript-6
ES6 发布时间2015-6月,又称ECMAScript 2015

http://kangax.github.io/compat-table/es6/

Set

var s = new Set();
[7,2,3,4,5,6,2,5].map( (item) => s.add(item));

for( let i of s ) {
	console.info(i);
}

结果:
7
2
3
4
5
6

实例属性与方法

操作方法

遍历方法

	数组去重
	function dedupe(array) {
		return Array.from( new Set(array) );
	}

WeakSet

区别于Set

var a= [[1,2],[3,4]];
var ws = new WeakSet(a);

Map

实例属性与操作方法

遍历方法
 var map = new Map([
	 [‘F‘, ‘no‘],
	 [‘T‘, ‘yes‘]
 ]);
 for( let [key, value] of map.entries() ) {
	 console.info(key , value);
 }

WeakMap

原文:https://www.cnblogs.com/pengsn/p/12874176.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!