If I have the following object:
const obj = {
nestedObj: {
foo: "bar",
}
}
and access one of the nested objects using obj.nestedObjA, will the resulting object contain some information of its key in the original object, or will it simply be the object literal { foo: "bar" }?
I would like to achieve something like this:
const fun = (nestedObj) => {
console.log(nestedObj.key); // print the key of obj in its parent object
console.log(nestedObj.foo);
}
without actually storing the key twice, e.g.:
const obj = {
nestedObjA: {
key: "nestedObjA", // I want to remove this line
foo: "bar",
}
}
fun(obj.nestedObjA);