# map.get()

The modified `map.get()` function returns the value associated with [`$key`](#usdkey) in [`$map`](#usdmap), and returns [`$fallback`](#usdfallback-null) if returned is `null`.

{% hint style="info" %}
Modified by removing arbitrary argument `$keys...` and instead, adding [`$fallback`](/sass/map/map.get.md#usdfallback-null) value. To get the nested value use key as comma-separated list. This way of providing key as comma-separated list is consistent with [`map.remove()`](/sass/map/map.remove.md) and [`map.set()`](/sass/map/map.set.md) functions.
{% endhint %}

{% code lineNumbers="true" %}

```scss
// Sass.
@use 'sass:list';
@use 'sass:map';
@use 'sass:meta';

// The `map.get()` function.
@function get($map, $key, $fallback: null) {
  @return if(
      meta.type-of($map) == map and list.length($key) > 0,
      if(
        list.separator($key) == comma,
        map.get($map, $key...),
        map.get($map, $key)
      ),
      $fallback
    )
    or $fallback;
}
```

{% endcode %}

{% embed url="<https://github.com/angular-package/sass/blob/main/map/_map.get.function.scss>" %}

### Parameters

#### `$map`

A map to get the value by using [`$key`](#usdkey).

#### `$key`

The key used to get the value from [`$map`](#usdmap).

#### `$fallback: null`

The fallback value if returned is `null`.

### Return

The return value is the value associated with [`$key`](#usdkey) from [`$map`](#usdmap), if `null` returns [`$fallback`](#usdfallback-null).

## Examples

```scss
// Use.
@use '@angular-package/sass/map';

// Examples.
$-map: (
  light theme: (
    primary palette: (
      primary: primary color,
      primary dark: primary color dark
    )
  ),
  (dark theme, normal theme): (
    silver: #f1f1f1,
    red: #d72000,
  )
);

// simple key
@debug map.get($-map, light theme); // (primary palette: (primary: primary color, primary dark: primary color dark))

// nested key
@debug map.get($-map, (light theme, primary palette)); // (primary: primary color, primary dark: primary color dark)

// null
@debug map.get($-map, wrong key); // null

// fallback
@debug map.get($-map, wrong key, (must be: this value)); // (must be: this value)

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.angular-package.dev/sass/map/map.get.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
