get-value-from-object
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

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





Package Sidebar

Install

npm i get-value-from-object

Weekly Downloads

76

Version

1.0.6

License

MIT

Unpacked Size

131 kB

Total Files

8

Last publish

Collaborators

  • sigka1234