Files
freeCodeCamp/guide/chinese/javascript/standard-objects/map/index.md
2018-10-16 21:32:40 +05:30

34 lines
556 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Map
localeTitle: 地图
---
## 地图
`[key, value]`条目的映射,其中键和值可以是任何值(对象和原始值)。
## 句法
```javascript
new Map([iterable])
```
## 参数
**iterable**一个Array或其他可迭代对象其元素是键值对。
## 例
```javascript
// basic usage
const myMap = new Map();
myMap.set('foo',1);
myMap.set('bar',2);
myMap.set('baz',3);
myMap.get('foo'); // returns 1
myMap.get('baz'); // returns 3
myMap.get('hihi'); // return undefined
myMap.size(); // 3
```