Set和Map的区别 (@es6)

Set结构是类似于数组结构,但是成员都是不重复的值

缺点是没办法像数组一样通过下标取值的方法.

构造:
let set = new Set([1,2,3]);
set.size    // 3

数组去重:
let arr = [1,2,3,4,5,4,23,1,3];
arr= Array.from(new Set(arr));  // [1, 2, 3, 4, 5, 23]

Map结构是键值对集合(Hash结构)

构造:
const map = new Map([
  ['name', '张三'],
  ['title', 'Author']
]);

map.size // 2
map.has('name') // true
map.get('name') // "张三"
map.has('title') // true
map.get('title') // "Author"
原文地址:https://www.cnblogs.com/IT123/p/10912160.html