SASS – get the last key from a map & get the last value from a map
Get last Key
Combine `nth()`, `map.keys()` and `length()`
nth(map_keys($map), length($map))
// example, bootstrap 4 `$grid-breakpoints`
nth(map_keys($grid-breakpoints), length($grid-breakpoints)) // xl
From last key, get last value
Known the key, get the value using `map.get()`
map_get($grid-breakpoints, nth(map_keys($grid-breakpoints), length($grid-breakpoints)));
// Or you can wrap the function at the top:
@function get-last-map-key($map) {
@return nth(map_keys($map), length($map));
}
// then use:
map_get($grid-breakpoints, get-last-map-key($grid-breakpoints));