Skip to content

Instantly share code, notes, and snippets.

@jdsteinbach
Created July 1, 2015 15:41
Show Gist options
  • Select an option

  • Save jdsteinbach/4b599e49e090d515669c to your computer and use it in GitHub Desktop.

Select an option

Save jdsteinbach/4b599e49e090d515669c to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
<p class="output">
The output number is
</p>
// ----
// libsass (v3.2.5)
// ----
/**
*
* Is there any way to fetch the last key and a specific key inside it?
*
**/
$map: (
key-1: (
first: true,
number: 1,
),
key-2: (
first: false,
number: 2,
),
);
// Map last key function by James Steinbach
@function map-last-key($map) {
$keys: map-keys($map);
@return nth($keys, length($keys));
}
// Get a specific value from the last nested map by James Steinbach
@function map-last-value($map, $sub-key) {
$last-value: map-get($map, map-last-key($map));
@return map-get($last-value, $sub-key);
}
// Map fetch function by Hugo Giraudel
@function map-fetch($map, $keys) {
@each $key in $keys {
$map: map-get($map, $key);
}
@return $map;
}
.output:after {
last-key: map-last-key($map);
last-value: map-last-value($map, number);
content: '' + map-fetch($map, key-2 number);
}
/**
*
* Is there any way to fetch the last key and a specific key inside it?
*
**/
.output:after {
last-key: key-2;
last-value: 2;
content: "2";
}
<p class="output">
The output number is
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment