dig
Gets the target value in a nested JSON object, based on the given key.
- Use the
in
operator to check iftarget
exists inobj
. - If found, return the value of
obj[target]
. - Otherwise use
Object.values(obj)
andArray.prototype.reduce()
to recursively calldig
on each nested object until the first matching key/value pair is found.