go语言 删除 int型切片的某个index的element

func sliceRemove(index int, s []int) ([]int, error) {
	//fmt.Println("len(slice) is ", len(s))
	if index > len(s)-1 || index < 0 {
		return nil, errors.New("index out of range")
	}
	if index == len(s)-1 {
		s = s[:index]
	} else {
		s = append(s[:index], s[index+1:]...)
	}
	//fmt.Println("s is : ", s)
	return s, nil
}

 

你可能感兴趣的:(go语言,删除切片的元素)