Help us understand the problem. What is going on with this article?

sliceからN番目の要素を削除する

More than 3 years have passed since last update.

簡単だけどすぐ忘れそう。

package main

import (
    "fmt"
)

func main() {
    t := []string{"0番目","1番目","2番目","3番目","4番目"}
    fmt.Println(t)
    n := 2
    fmt.Printf("%d番目を削除\n", n)
    t = unset(t, n)
    fmt.Println(t)
}

func unset(s []string, i int) []string {
    if i >= len(s) {
        return s
    }
    return append(s[:i], s[i+1:]...)
}

https://play.golang.org/p/53J04UE7dv

usk81
お仕事内容:プログラマ & たまにインフラ & SEOラングラー & データアナリスト & データサイエンティスト見習い & バリスタじゃないけど、コーヒー淹れる人 & 農家から買い付けて日本茶淹れる人
https://usk81.dev
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away