Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6: Set与Map #46

Open
sfsoul opened this issue Dec 21, 2019 · 0 comments
Open

ES6: Set与Map #46

sfsoul opened this issue Dec 21, 2019 · 0 comments
Labels

Comments

@sfsoul
Copy link
Owner

sfsoul commented Dec 21, 2019

产生原因

JavaScript的默认对象表示方式 {} 可以视为其他语言中的 MapDictionary 的数据结构,即一组键值对。但是 JavaScript 的对象有个小问题,即键必须是字符串。但实际上Number或者其他数据类型作为键也是非常合理的。为了解决这个问题,最新的ES6规范引入了新的数据类型MapSet

Set是一种叫做集合的数据结构,Map是一种叫做字典的数据结构

应用场景

数组去重

const array = [2,3,5,4,5,2,2];
const newArray = [...new Set(array)]; // [2,3,5,4]

模拟实现 Set

@sfsoul sfsoul added the ES6 label Dec 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant