Installations
npm install @stdlib/utils-deep-pluck
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=0.10.0
Node Version
16.20.2
NPM Version
8.19.4
Score
70.7
Supply Chain
88.1
Quality
82.3
Maintenance
100
Vulnerability
88
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
3,813
Last Day
3
Last Week
16
Last Month
84
Last Year
676
GitHub Statistics
Apache-2.0 License
2 Stars
67 Commits
3 Watchers
5 Branches
11 Contributors
Updated on Feb 03, 2025
Sponsor this package
Package Meta Information
Latest Version
0.2.2
Package Id
@stdlib/utils-deep-pluck@0.2.2
Unpacked Size
40.36 kB
Size
10.53 kB
File Count
13
NPM Version
8.19.4
Node Version
16.20.2
Published on
Jul 27, 2024
Total Downloads
Cumulative downloads
Total Downloads
3,813
Last Day
50%
3
Compared to previous day
Last Week
-11.1%
16
Compared to previous week
Last Month
20%
84
Compared to previous month
Last Year
-44.5%
676
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Deep Pluck
Extract a nested property value from each element of an object array.
Installation
1npm install @stdlib/utils-deep-pluck
Usage
1var deepPluck = require( '@stdlib/utils-deep-pluck' );
deepPluck( arr, path[, options] )
Extracts a nested property value from each element of an object array
based on a key path
.
1var arr = [ 2 { 'a': { 'b': { 'c': 1 } } }, 3 { 'a': { 'b': { 'c': 2 } } } 4]; 5 6var out = deepPluck( arr, 'a.b.c' ); 7// returns [ 1, 2 ]
A key path
may be specified as either a string
or as an array
.
1var arr = [ 2 { 'a': [ 0, 1, 2 ] }, 3 { 'a': [ 3, 4, 5 ] } 4]; 5 6var out = deepPluck( arr, [ 'a', 1 ] ); 7// returns [ 1, 4 ]
The function accepts the following options
:
- copy:
boolean
indicating whether to return a new data structure. Default:true
. - sep: key path separator. Default:
'.'
.
By default, the function returns a new data structure. To mutate the input data structure (e.g., when input values can be discarded or when optimizing memory usage), set the copy
option to false
.
1var arr = [ 2 { 'a': { 'b': { 'c': 1 } } }, 3 { 'a': { 'b': { 'c': 2 } } } 4]; 5 6var out = deepPluck( arr, 'a.b.c', { 'copy': false } ); 7// returns [ 1, 2 ] 8 9var bool = ( arr[ 0 ] === out[ 0 ] ); 10// returns true
The default key path
separator is .
. To specify an alternative separator, set the sep
option.
1var arr = [ 2 { 'a': { 'b': { 'c': 1 } } }, 3 { 'a': { 'b': { 'c': 2 } } } 4]; 5 6var out = deepPluck( arr, 'a|b|c', { 'sep': '|' } ); 7// returns [ 1, 2 ]
-
If a key path does not exist, the function sets the plucked value as
undefined
.1var arr = [ 2 { 'a': { 'b': { 'c': 1 } } }, 3 null, 4 void 0, 5 { 'a': { 'b': { 'c': 2 } } } 6]; 7 8var out = deepPluck( arr, 'a.b.c' ); 9// returns [ 1, undefined, undefined, 2 ]
-
Extracted values are not cloned.
1var arr = [ 2 { 'a': { 'b': { 'c': 2 } } }, 3 { 'a': { 'b': { 'c': 3 } } } 4]; 5 6var out = deepPluck( arr, 'a.b' ); 7// returns [ { 'c': 2 }, { 'c': 3 } ] 8 9var bool = ( arr[ 0 ].a.b === out[ 0 ] ); 10// returns true
To prevent subsequent unintended mutation, use copy.
1var copy = require( '@stdlib/utils-copy' ); 2 3var arr = [ 4 { 'a': { 'b': { 'c': 2 } } }, 5 { 'a': { 'b': { 'c': 3 } } } 6]; 7 8var out = deepPluck( arr, 'a.b' ); 9// returns [ { 'c': 2 }, { 'c': 3 } ] 10 11// Perform a deep copy: 12out = copy( out ); 13 14var bool = ( arr[ 0 ].a.b === out[ 0 ] ); 15// returns false
Examples
1var randu = require( '@stdlib/random-base-randu' ); 2var round = require( '@stdlib/math-base-special-round' ); 3var deepPluck = require( '@stdlib/utils-deep-pluck' ); 4 5var arr; 6var out; 7var tmp; 8var i; 9 10arr = new Array( 100 ); 11for ( i = 0; i < arr.length; i++ ) { 12 tmp = { 13 'a': { 14 'b': { 15 'c': { 16 'd': null 17 } 18 } 19 } 20 }; 21 tmp.a.b.c.d = round( randu()*100.0 ); 22 arr[ i ] = tmp; 23} 24 25// Pluck the deeply nested values: 26out = deepPluck( arr, 'a.b.c.d' ); 27console.log( out );
See Also
@stdlib/utils-deep-get
: get a nested property value.@stdlib/utils-deep-set
: set a nested property value.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:85: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-deep-pluck/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:275: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-deep-pluck/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:449: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-deep-pluck/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:457: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-deep-pluck/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:623: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-deep-pluck/productionize.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:165
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:83
- Warn: npmCommand not pinned by hash: .github/workflows/test_bundles.yml:72
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:74
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_published_package.yml:93
- Info: 33 out of 33 GitHub-owned GitHubAction dependencies pinned
- Info: 19 out of 24 third-party GitHubAction dependencies pinned
- Info: 0 out of 32 npmCommand dependencies pinned
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/benchmark.yml:1
- Warn: no topLevel permission defined: .github/workflows/cancel.yml:1
- Warn: no topLevel permission defined: .github/workflows/close_pull_requests.yml:1
- Warn: no topLevel permission defined: .github/workflows/examples.yml:1
- Warn: no topLevel permission defined: .github/workflows/npm_downloads.yml:1
- Warn: no topLevel permission defined: .github/workflows/productionize.yml:1
- Warn: no topLevel permission defined: .github/workflows/publish.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_bundles.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_coverage.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_install.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_published_package.yml:1
- Info: no jobLevel write permissions found
Score
4.4
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More