JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2185713
  • Score
    100M100P100Q193139F
  • License MIT

Access deep properties using a path

Package Exports

  • object-path

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-path) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

object-path

Access deep properties using a path

NPM

Build Status Coverage Status devDependency Status

browser support

Install

Node.js

npm install object-path

Browser

bower install object-path

Usage

var obj = {
  a: {
    b: "d",
    c: ["e", "f"]
  }
};

var objectPath = require("object-path");

//get deep property
objectPath.get(obj, "a.b");  //returns "d"

//works also with arrays
objectPath.get(obj, "a.c.1");  //returns "f"

//set
objectPath.set(obj, "a.h", "m");
objectPath.get(obj, "a.h");  //returns "m"

//set will create intermediate object/arrays
objectPath.set(obj, "a.j.0.f", "m");

//push into arrays (and create intermediate objects/arrays)
objectPath.push(obj, "a.k", "o");

//Ensure a path exists (if it doesn't, set the default value you provide)
objectPath.ensureExists(obj, "a.k.1", "DEFAULT");