Skip to main content

at()

at<T>(object, paths): unknown[]

Creates an array of values corresponding to paths of object.

DEPRECATED

Use paths.map(p => get(obj, p)) directly instead.


Type Parameters​

T: T​


Parameters​

object: T​

The object to iterate over.

paths: readonly (string | (string | number | symbol)[])[]​

The property paths to pick.


Returns: unknown[]​

An array of resolved values.


See Also​

get


Since​

2.0.0


Also known as​

at (Lodash, es-toolkit) · paths (Ramda) · ❌ (Remeda, Radashi, Effect, Modern Dash, Antfu)


Example​

const object = { a: [{ b: { c: 3 } }, 4] };

// ❌ Deprecated approach
at(object, ['a[0].b.c', 'a[1]']);
// => [3, 4]

// βœ… Recommended approach
['a[0].b.c', 'a[1]'].map(p => get(object, p));
// => [3, 4]

How it works?​

Creates an array of values at specified paths.

Processing Flow​

Common Inputs​

ObjectPathsResult
{a: [{b: {c: 3}}, 4]}['a[0].b.c', 'a[1]'][3, 4]
{x: 1, y: 2}['x', 'y', 'z'][1, 2, undefined]

Deprecated: Use paths.map(p => get(obj, p)) directly.


Use Cases​

Get values at paths πŸ“Œβ€‹

Get values at multiple paths.

import { get } from '@pithos/arkhe';
const paths = ['a.b', 'c.d'];
const values = paths.map(p => get(obj, p));

Extract specific fields​

Extract specific nested values.

import { get } from '@pithos/arkhe';
const fields = ['user.name', 'user.email'];
const data = fields.map(f => get(response, f));