Use list(target, query, options?) to return all properties matching the query as an array.
Supported query types include:
- Unions: Space-separated paths (e.g.,
'path.one path.two'). - Arrays of paths:
[['path', 'one'], ['path', 'two']]. - Regexps: Using regex patterns (e.g.,
'user./Name/'). - Wildcards:
* or **. - Slices:
0:2.
If { entries: true } is passed in options, it returns an array of objects containing { value, path, missing } instead of just values.
const target = {
userOne: { firstName: 'John', lastName: 'Doe', age: 72 },
userTwo: { firstName: 'Alice', colors: ['red', 'blue', 'yellow'] },
}
list(target, 'userOne.firstName userTwo.colors.0') // ['John', 'red']
list(target, [['userOne', 'firstName'], ['userTwo', 'colors', 0]]) // ['John', 'red']
list(target, 'userOne./Name/') // ['John', 'Doe']
list(target, ['userOne', /Name/]) // ['John', 'Doe']
list(target, 'userTwo.colors.*') // ['red', 'blue', 'yellow']
list(target, 'userTwo.colors.0:2') // ['red', 'blue']
list(target, '**.firstName') // ['John', 'Alice']
list(target, 'userOne.*', { entries: true })
// [
// { value: 'John', path: ['userOne', 'firstName'], missing: false },
// { value: 'Doe', path: ['userOne', 'lastName'], missing: false },
// { value: 72, path: ['userOne', 'age'], missing: false },
// ]