Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Golang copy map object properties to another map object (js destructing equivalent)
package main
import "fmt"
func main() {
person := map[string]interface{}{
"name": "test",
"age": 13,
"school": "stanford",
student := map[string]interface{}{
"school": "harvard",
for k, v := range person {
if _, ok := student[k]; !ok {
student[k] = v
fmt.Println(student) // map[age:13 name:test school:harvard]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.