> For the complete documentation index, see [llms.txt](https://ryanyang.gitbook.io/the-way-to-go-zh-cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ryanyang.gitbook.io/the-way-to-go-zh-cn/di-si-bu-fen-shi-ji-ying-yong/18.0/18.3.md).

# 映射

创建： `map1 := make(map[keytype]valuetype)`

初始化： `map1 := map[string]int{"one": 1, "two": 2}`

（1）如何使用`for`或者`for-range`遍历一个映射：

```go
for key, value := range map1 {
…
}
```

（2）如何在一个映射中检测键`key1`是否存在：

`val1, isPresent = map1[key1]`

返回值：键`key1`对应的值或者`0`, `true`或者`false`

（3）如何在映射中删除一个键：

`delete(map1, key1)`

## 链接

* [目录](https://github.com/yangchuansheng/the-way-to-go_ZH_CN/tree/f30ab7d8c58f85840a0afb548024b93642b518d5/eBook/directory.md)
* 上一节：[数组和切片](/the-way-to-go-zh-cn/di-si-bu-fen-shi-ji-ying-yong/18.0/18.2.md)
* 下一节：[结构体](/the-way-to-go-zh-cn/di-si-bu-fen-shi-ji-ying-yong/18.0/18.4.md)
