how to change the key value of gdscript dictionary?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Thakee Nathees

i have a dictionary like below

var dict = { "key1": "val1", "key2":"val2" }

and i want to change the name of the key1 without changing anything else like

dict = { "key1_changed": "val1", "key2":"val2" }

how to do this?

:bust_in_silhouette: Reply From: kidscancode

Add the new key and remove the old one:

dict["key_changed"] = dict["key1"]
dict.erase("key1")
1 Like