freeCodeCamp/guide/chinese/javascript/standard-objects/map/index.md

34 lines
556 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
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
```