Skip to content

sbmelvin/propertyWithPath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

propertyWithPath

A JS method to check for the existence of a property deep within a JS Object. Paths are key values or array indicies separated by periods.

Returns: The value of the property if it exists, otherwise it returns undefined.

Example Usage:

var x = { 
    y: 5
};

propertyWithPath(x, "y"); //Returns 5

propertyWithPath(x, "y.z"); //Returns undefined


var x = {
    y: ['moe', 'larry', 'curly', { z: 'shemp' } ]
};

propertyWithPath(x, "y.0"); //Returns 'moe'
propertyWithPath(x, "y.3.z"); //Returns 'shemp'
propertyWithPath(x, "y.2.z"); //Returns undefined

About

A JS method to check for the existence of a property deep within a JS Object.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published