Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

get-value-from-object

sigka1234100MIT1.0.6TypeScript support: included

null

node, react, react-native, get, value, object, get-object, get-value, get-object-value, get-value-object, object parsing, parsing, parse

readme

get-value-from-object

- Get Data from Object Without Error



installing


npm:

npm install get-value-from-object

yarn:

yarn add get-value-from-object

import

import get from "get-value-from-object"  

var get = require("get-value-from-object")

Usage

const object = {
    name: "John",
    birth: { age: 25, day: "1999-01-01" },
    hobbies: [
        "running",
        { kind: "camera", model: "canon 5d" },
        ["sing", { title: "Let it be!" }],
    ]
}
get(object, "name") // John
get(object, "birth.age") // 25
get(object, "hobbies[0]") // running
get(object, "hobbies[1].model") // canon 5d
get(object, "hobbies[2][0]") // sing
get(object, "hobbies[2][1].title") // Let it be!

// set for default values
get(object, "name2", null) // null
get(object, "birth.age", 29) // 25
get(object, "birth.age.my", 29) // 29