go array에서 element 삭제하기

chacha·2020년 7월 24일
0

go알고리즘

목록 보기
4/8

source

urlList := []string{"test", "abc", "def", "ghi"}
remove := []string{"abc", "test"}

loop:
for i := 0; i < len(urlList); i++ {
    url := urlList[i]
    for _, rem := range remove {
        if url == rem {
            urlList = append(urlList[:i], urlList[i+1:]...)
            i-- // Important: decrease index
            continue loop
        }
    }
}

fmt.Println(urlList)

output

[def ghi]
profile
안녕하세요~ :)

0개의 댓글