map.deep-remove($map, $key, $keys...) returns a new map without the targeted key. With only $key, it drops a top-level entry. With extra $keys, it walks nested maps and removes the last key in the path. Load it with @use "sass:map" on Dart Sass 1.27+. There is no separate global deep-remove().
Official samples.
Flat: map.deep-remove(("regular": 400, "medium": 500, "bold": 700), "regular") → ("medium": 500, "bold": 700). Nested: pass "Helvetica", "weights", "regular" to drop only that weight.
Path = walk then delete.
Keys before the last one locate the nested map. The last key is the entry that gets removed.
Immutable result.
Original maps stay unchanged. Reassign when you want to keep the cleanup: $theme: map.deep-remove($theme, colors, accent);
Syntax
Syntax
SCSS
@use "sass:map";
// Top-level key
map.deep-remove($map, $key);
// Nested path — last key is removed
map.deep-remove($map, $key, $keys...);
map.deep-remove($fonts, "Helvetica", "weights", "regular");
// removes only "regular" inside Helvetica → weights
Pattern: locate with a key path → map.deep-remove → confirm with map.has-key or map.get.
Reference
Path Rules
Choose the helper based on how deep the key lives:
Goal
Use
Drop one nested leaf
map.deep-remove($map, $k1, $k2, $leaf)
Drop a whole nested branch
map.deep-remove($map, $parent, $branch)
Drop one or more top-level keys
map.remove($map, $keys...)
Single top-level key
Either deep-remove or remove
Missing leaf key
Safe — returns an equivalent copy
Global deep-remove()
Not provided — module only
vs map.remove.
map.remove only touches top-level keys. To delete colors.accent without wiping colors, you need map.deep-remove.
Removes by key path without rebuilding the whole map.
Last key is deleted; earlier keys only navigate.
Deeper than map.remove — keeps sibling nested keys.
Module only — Dart Sass 1.27+, no global helper.
One line: when a nested token must go, call map.deep-remove($map, $path..., $leaf).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:map"
2. Use deep-remove for nested leaves; remove for top-level keys
3. Remember: last key in the path is deleted
4. Reassign: $map: map.deep-remove($map, ...)
5. Confirm with map.has-key / map.get
Frequently Asked Questions
map.deep-remove($map, $key, $keys...) returns a new map without the targeted key. With only $key it removes a top-level entry. With extra $keys it walks nested maps and removes the last key in the path.
map.remove deletes one or more top-level keys only. map.deep-remove can dig into nested maps using a key path, so you can drop colors.accent without deleting the whole colors map.
Removing a missing leaf key is safe: you get a copy that still looks like the original map for that path.
No. It returns a new map. Reassign if you need to keep the result: $theme: map.deep-remove($theme, colors, accent).
No. Use map.deep-remove() after @use "sass:map" (or @use "sass:map" as * and call deep-remove()).
Dart Sass 1.27+. LibSass and Ruby Sass do not provide this deep helper—prefer current Dart Sass.