GoLang 遍历 map、slice、array方法和template遍历map

GoLang 遍历 map、slice、array方法

map1 := make(map[string]string)
    map1["a"] = "AAA"
    map1["b"] = "BBB"
    map1["c"] = "CCC"
    for k, v := range map1 {
        t.Log(k, v)
    }
    for _, v := range map1 {
        t.Log(v)
    }

    array := [...]int64{1, 2, 3, 4}
    for k, v := range array {
        t.Log(k, v)
    }
    for _, v := range array {
        t.Log(v)
    }

    slice := array[:3:3]
    for k, v := range slice {
        t.Log(k, v)
    }
    t.Log(cap(slice))
    slice[0] = 444
    slice = append(slice, 888)
    slice = append(slice, 999)
    t.Log(slice)
    t.Log(array)


template遍历map

  {{range $key, $value := .Header }}
            Key:{{$key}}, value:{{$value}} 
{{end}}









你可能感兴趣的:(golang)