How to remove a key from a map/dict?

Hi, I want to delete some keys from a dict, is there any function for this?

{{ $m := dict "foo" "bar" "fizz" "buzz" }}

Remove the fizz as below.

{{ dict "foo" "bar" }}

EDITED

The map/dict comes from the configuration, I wish to transform it before passing it to partials, for compatibility.

1 Like

This is a bit clumsy, but…

{{ $m := dict "foo" "bar" "fizz" "buzz" }}

{{ $ls := newScratch }}
{{ $ls.Set "cfg" $m  }}
{{ $ls.DeleteInMap "cfg" "fizz" }}

{{ $ls.Values.cfg }} --> map[foo:bar]
2 Likes

Thank you.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.