提交 a368932d 编写于 作者: 杜庆泉's avatar 杜庆泉

Update map.md

上级 a9911709
......@@ -90,3 +90,33 @@ console.log(map1.get('bar'));
console.log(map1.get('baz'));
// expected output: null
```
### 常见操作
- 创建map
```ts
let map = new Map<string,any>()
map.put("name","zhangsan")
map.put("age",12)
//Map(2) {"name":"zhangsan","age":12}
console.log(map)
```
- 通过key访问map元素
```ts
let map = new Map<string,any>()
map.put("name","zhangsan")
map.put("age",12)
let nameVal = map['name']
//zhangsan
console.log(nameVal)
```
- 遍历map
```ts
let map = new Map<string,any>()
map.put("name","zhangsan")
map.put("age",12)
map.forEach(function(key:string,value:any){
console.log(key)
console.log(value)
})
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册