Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Oct 1, 2022. It is now read-only.
/dot2valPublic archive

Set or get a value within a deeply nested object using `dot' notation

NotificationsYou must be signed in to change notification settings

yangg/dot2val

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusTest CoverageCode Climatenpm:

Set or get a value within a deeply nested object using `dot' notation

Installation

npm install --save dot2val

Usage

vardot2val=require('dot2val');

Given:

varobj={prop1:{arr:['a','b','c'],str:'Hello'},prop2:{arr:[{nested:'Universe'}],str:'Hello again!'}}vararr=[{foo:'bar'}];

Expect:

get

dot2val.get(obj,'prop1.str');// => "Hello"dot2val.get(obj,'prop1.arr.2');// => "c"dot2val.get(obj,'prop2.arr.0.nested');// => "Universe"dot2val.get(arr,'0.foo');// => "bar"dot2val.get(undefined,'doesnt.matter');// => undefineddot2val.get({},'doesnt.exist');// => undefineddot2val.get({},'doesnt.exist','default value');// => "default value"

set

dot2val.set(obj,'hello.universe','properties');dot2val.set(obj,'hello1','universe');dot2val.set(obj,'prop2');// delete obj['prop2']

Try dot2val in your browser

License

MIT

About

Set or get a value within a deeply nested object using `dot' notation

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp