# selection.Selection

- **Module:** selection
- **Package:** libtmux
- **Language:** TypeScript
- **Kind:** interface
- **Source:** https://github.com/libtmux/libtmux-ts/blob/46cccfef2a546de55ce8b308249b8c76339089a0/packages/libtmux/src/selection.ts#L415
- **Page:** https://libtmux.org/en/ts/latest/reference/selection-selection/

An immutable, ordered set of tmux objects read at one instant.

A Selection is deliberately not an Array. It is [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol) and it never
changes, so the answer it gave a moment ago is still the answer now — which
is what lets a snapshot be reasoned about at all. [`toArray()`](/en/ts/latest/reference/selection-selection-toarray/) is the one
crossing to array semantics, and everything Array offers that this does not
lives on the other side of it.

Two ways to narrow, never overloaded into each other: [`where`](/en/ts/latest/reference/selection-selection-where/) takes
declarative criteria that are data — serializable, inspectable, sendable over
a wire — and [`filter`](/en/ts/latest/reference/selection-selection-filter/) takes an ordinary predicate. Reach for [`where`](/en/ts/latest/reference/selection-selection-where/) unless
the question genuinely needs to run code.

## Type parameters

- `Model`

## Members

### Common operations

- [`one`](/en/ts/latest/reference/selection-selection-one/) (method): The single member, or the single one matching `criteria`.
- [`exists`](/en/ts/latest/reference/selection-selection-exists/) (method): Whether anything matches. Cheaper to read than comparing a count to zero.
- [`filter`](/en/ts/latest/reference/selection-selection-filter/) (method): Keep the members `predicate` accepts.
- [`first`](/en/ts/latest/reference/selection-selection-first/) (method): The first member, or the first matching `criteria`.
- [`oneOrUndefined`](/en/ts/latest/reference/selection-selection-oneorundefined/) (method): The single member, or undefined when there is none.
- [`where`](/en/ts/latest/reference/selection-selection-where/) (method): Keep the members matching declarative criteria.
- [`[Symbol.iterator]`](/en/ts/latest/reference/selection-selection-[symbol-iterator]/) (method): Iterate in tmux's own order.
- [`at`](/en/ts/latest/reference/selection-selection-at/) (method): The member at `index`, or undefined when the index is out of range.
- [`count`](/en/ts/latest/reference/selection-selection-count/) (method): How many members match `criteria`, or how many there are without it.
- [`length`](/en/ts/latest/reference/selection-selection-length/) (property): How many members this holds. Unlike `count`, it takes no criteria.
- [`map`](/en/ts/latest/reference/selection-selection-map/) (method): Apply `transform` to each member, in order.
- [`toArray`](/en/ts/latest/reference/selection-selection-toarray/) (method): A plain array of the members, in order.

## Guides

Pages that discuss `Selection`.

### Concepts

- [Filtering and queries](/en/ts/latest/concepts/queries/)

### Topics

- [Traversal](/en/ts/latest/topics/traversal/)
