# Selection

[Selection](https://api.activejs.dev/classes/selection.html) is a simple construct that operates on a nested property in the non-primitive Units' value, i.e.: [ListUnit](https://docs.activejs.dev/activejs/fundamentals/units/listunit), [GenericUnit](https://docs.activejs.dev/activejs/fundamentals/units/genericunit), and [DictUnit](https://docs.activejs.dev/activejs/fundamentals/units/dictunit).

Selection offers the ability to access and observe a nested property at a certain path in a Unit's value.

### Make a Selection

```typescript
// create a Unit
const preferencesUnit = new DictUnit({initialValue: 
  {color: 'blue', music: 'EDM', game: 'GTA5'}
})

// make a selection
// the 'select' method takes path as it's params
const musicPreference = preferencesUnit.select('music')
```

### Static Value Access

After creating a Selection object, we can access the value at the selected path anytime, without worrying if the value still exists or not.

```typescript
// access the value at the selected path
console.log(musicPreference.value())
// logs 'EDM' immediately
```

### Reactive Value Access

To observe the value over time we can make an Observable at the selected path, and subscribe to it.

```typescript
// create an Observable
const musicPreference$ = musicPreference.asObservable()

// subsribe for reactive access
musicPreference$.subscribe(value => console.log(value))
// logs 'EDM' immediately, and
// will log whenever the value at the selected path changes
```


---

# 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.activejs.dev/activejs/utilities/selection.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.
