title: How to remove element of struct array in loop in golang
body: <p><strong>Problem</strong></p>
  
  <p>I have array of structs:</p>
  
  <pre><code>type Config struct {
    Applications []Application
  }
  </code></pre>
  
  <p>Note: Config - is a struct for json.Decode.</p>
  
  <pre><code>config = new(Config)
  _ = decoder.Decode(&amp;config)
  </code></pre>
  
  <p>In loop I have some condition and element deletion by key.</p>
  
  <pre><code>for i, application := range config.Applications {
    if i == 1 {
      config.Applications = _removeApplication(i, config.Applications)
    }
  }
  
  func _removeApplication(i int, list []Application) []Application {
    if i &lt; len(list)-1 {
      list = append(list[:i], list[i+1:]...)
    } else {
      log.Print(list[i].Name)
      list = list[:i]
    }
  
    return list
  }
  </code></pre>
  
  <p>But always I have "out of range" error. What is the best way to delete element by key from array of structs?</p>