const {dig, digg, digs} = require("diggerize")
import {dig, digg, digs} from "diggerize"
Traverses through objects to find the given path.
const myObject = {
people: [
{
firstName: "Kasper",
lastName: "Nielsen"
}
]
}
dig(myObject, "people", 0, "firstName") //=> "Kasper"
dig(myObject, "people", 1, "firstName") //=> null
This functions like dig
but it will fail if one of the keys isn't found.
const myObject = {
people: [
{
firstName: "Kasper",
lastName: "Nielsen"
}
]
}
digg(myObject, "people", 0, "firstName") //=> "Kasper"
digg(myObject, "people", 1, "firstName") //=> Fails because 1 isn't found in the people array
This will fail is object
doesn't contain keys named firstKey
and secondKey
.
const {firstKey, secondKey} = digs(object, "firstKey", "secondKey")