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โ
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โ
| Object | Paths | Result |
|---|---|---|
{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));
Deprecated: Use