Gathering detailed insights and metrics for get-value
Gathering detailed insights and metrics for get-value
Gathering detailed insights and metrics for get-value
Gathering detailed insights and metrics for get-value
union-value
Set an array of unique values as the property of an object. Supports setting deeply nested properties using using object-paths/dot notation.
set-value
Set nested properties on an object using dot notation.
jest-get-type
A utility function to get the type of a value
is-accessor-descriptor
Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
Use property paths (`a.b.c`) get a nested value from an object.
npm install get-value
Typescript
Module System
Node Version
NPM Version
JavaScript (52.26%)
TypeScript (47.74%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
288 Stars
103 Commits
21 Forks
9 Watchers
3 Branches
7 Contributors
Updated on Jun 29, 2025
Latest Version
4.0.1
Package Id
get-value@4.0.1
Unpacked Size
23.27 kB
Size
6.69 kB
File Count
6
NPM Version
10.9.2
Node Version
22.13.0
Published on
Feb 05, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Use property paths like 'a.b.c' to get a nested value from an object. Even works when keys have dots in them (no other dot-prop library we tested does this, or does it correctly).
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
1$ npm install --save get-value
See the unit tests for many more examples.
1const get = require('get-value');
2const obj = { a: { b: { c: { d: 'foo' } } } };
3
4console.log(get(obj)); //=> { a: { b: { c: { d: 'foo' } } } };
5console.log(get(obj, 'a')); //=> { b: { c: { d: 'foo' } } }
6console.log(get(obj, 'a.b')); //=> { c: { d: 'foo' } }
7console.log(get(obj, 'a.b.c')); //=> { d: 'foo' }
8console.log(get(obj, 'a.b.c.d')); //=> 'foo'
Unlike other dot-prop libraries, get-value works when keys have dots in them:
1console.log(get({ 'a.b': { c: 'd' } }, 'a.b.c')); 2//=> 'd' 3 4console.log(get({ 'a.b': { c: { 'd.e': 'f' } } }, 'a.b.c.d.e')); 5//=> 'f'
1console.log(get({ a: { b: { c: { d: 'foo' } } }, e: [{ f: 'g' }, { f: 'h' }] }, 'e.1.f')); 2//=> 'h' 3 4console.log(get({ a: { b: [{ c: 'd' }] } }, 'a.b.0.c')); 5//=> 'd' 6 7console.log(get({ a: { b: [{ c: 'd' }, { e: 'f' }] } }, 'a.b.1.e')); 8//=> 'f'
1function foo() {} 2foo.bar = { baz: 'qux' }; 3 4console.log(get(foo)); 5//=> { [Function: foo] bar: { baz: 'qux' } } 6 7console.log(get(foo, 'bar')); 8//=> { baz: 'qux' } 9 10console.log(get(foo, 'bar.baz')); 11//=> qux
Slighly improve performance by passing an array of strings to use as object path segments (this is also useful when you need to dynamically build up the path segments):
1console.log(get({ a: { b: 'c' } }, ['a', 'b'])); 2//=> 'c'
Type: any
Default: undefined
The default value to return when get-value cannot resolve a value from the given object.
1const obj = { foo: { a: { b: { c: { d: 'e' } } } } };
2console.log(get(obj, 'foo.a.b.c.d', { default: true })); //=> 'e'
3console.log(get(obj, 'foo.bar.baz', { default: true })); //=> true
4console.log(get(obj, 'foo.bar.baz', { default: false })); //=> false
5console.log(get(obj, 'foo.bar.baz', { default: null })); //=> null
6
7// you can also pass the default value as the last argument
8// (this is necessary if the default value is an object)
9console.log(get(obj, 'foo.a.b.c.d', true)); //=> 'e'
10console.log(get(obj, 'foo.bar.baz', true)); //=> true
11console.log(get(obj, 'foo.bar.baz', false)); //=> false
12console.log(get(obj, 'foo.bar.baz', null)); //=> null
Type: function
Default: true
If defined, this function is called on each resolved value. Useful if you want to do .hasOwnProperty
or Object.prototype.propertyIsEnumerable
.
1const isEnumerable = Object.prototype.propertyIsEnumerable; 2const options = { 3 isValid: (key, obj) => isEnumerable.call(obj, key) 4}; 5 6const obj = {}; 7Object.defineProperty(obj, 'foo', { value: 'bar', enumerable: false }); 8 9console.log(get(obj, 'foo', options)); //=> undefined 10console.log(get({}, 'hasOwnProperty', options)); //=> undefined 11console.log(get({}, 'constructor', options)); //=> undefined 12 13// without "isValid" check 14console.log(get(obj, 'foo', options)); //=> bar 15console.log(get({}, 'hasOwnProperty', options)); //=> [Function: hasOwnProperty] 16console.log(get({}, 'constructor', options)); //=> [Function: Object]
Type: function
Default: String.split()
Custom function to use for splitting the string into object path segments.
1const obj = { 'a.b': { c: { d: 'e' } } }; 2 3// example of using a string to split the object path 4const options = { split: path => path.split('/') }; 5console.log(get(obj, 'a.b/c/d', options)); //=> 'e' 6 7// example of using a regex to split the object path 8// (removing escaped dots is unnecessary, this is just an example) 9const options = { split: path => path.split(/\\?\./) }; 10console.log(get(obj, 'a\\.b.c.d', options)); //=> 'e'
Type: string|regex
Default: .
The separator to use for spliting the string (this is probably not needed when options.split
is used).
1const obj = { 'a.b': { c: { d: 'e' } } }; 2 3console.log(get(obj, 'a.b/c/d', { separator: '/' })); 4//=> 'e' 5 6console.log(get(obj, 'a\\.b.c.d', { separator: /\\?\./ })); 7//=> 'e'
Type: function
Default: Array.join()
Customize how the object path is created when iterating over path segments.
1const obj = { 'a/b': { c: { d: 'e' } } }; 2const options = { 3 // when segs === ['a', 'b'] use a "/" to join, otherwise use a "." 4 join: segs => segs.join(segs[0] === 'a' ? '/' : '.') 5}; 6 7console.log(get(obj, 'a.b.c.d', options)); 8//=> 'e'
Type: string
Default: .
The character to use when re-joining the string to check for keys with dots in them (this is probably not needed when options.join
is used). This can be a different value than the separator, since the separator can be a string or regex.
1const target = { 'a-b': { c: { d: 'e' } } }; 2const options = { joinChar: '-' }; 3console.log(get(target, 'a.b.c.d', options)); 4//=> 'e'
(benchmarks were run on a MacBook Pro 2.5 GHz Intel Core i7, 16 GB 1600 MHz DDR3).
get-value is more reliable and has more features than dot-prop, without sacrificing performance.
# deep (338 bytes)
dot-prop x 2,524,501 ops/sec ±3.47% (90 runs sampled)
dotty x 1,990,042 ops/sec ±1.10% (91 runs sampled)
get-value x 3,776,247 ops/sec ±0.71% (98 runs sampled)
getobject x 1,166,194 ops/sec ±2.94% (94 runs sampled)
object-path x 975,380 ops/sec ±0.27% (97 runs sampled)
fastest is get-value (by 50% avg)
# root (215 bytes)
dot-prop x 18,774,512 ops/sec ±0.67% (95 runs sampled)
dotty x 16,732,378 ops/sec ±0.66% (95 runs sampled)
get-value x 35,516,146 ops/sec ±1.16% (92 runs sampled)
getobject x 7,743,671 ops/sec ±2.99% (95 runs sampled)
object-path x 11,955,285 ops/sec ±0.48% (95 runs sampled)
fastest is get-value (by 89% avg)
# shallow (91 bytes)
dot-prop x 10,195,874 ops/sec ±0.88% (95 runs sampled)
dotty x 8,383,019 ops/sec ±0.81% (97 runs sampled)
get-value x 9,891,229 ops/sec ±0.88% (90 runs sampled)
getobject x 4,333,202 ops/sec ±1.52% (99 runs sampled)
object-path x 4,568,894 ops/sec ±1.60% (94 runs sampled)
fastest is dot-prop (by 3% avg)
Clone this library into a local directory:
1$ git clone https://github.com/jonschlinkert/get-value.git
Then install devDependencies and run benchmarks:
1$ npm install && node benchmark
options.default
for defining a default value to return when no value is resolved.options.isValid
to allow the user to check the object after each iteration.options.separator
for customizing character to split on.options.split
for customizing how the object path is split.options.join
for customizing how the object path is joined when iterating over path segments.options.joinChar
for customizing the join character.Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
key
exists deeply on the given object. | homepageCommits | Contributor |
---|---|
93 | jonschlinkert |
2 | doowb |
2 | felladrin |
1 | onokumus |
1 | joepie91 |
1 | sonofmagic |
Jon Schlinkert
Copyright © 2025, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on February 05, 2025.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
6 existing vulnerabilities detected
Details
Reason
Found 5/23 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
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