Message from JavaScript discussions

April 2018

— If it's a value, you can't

— 

If it's a property AND you have access to the parent object, you might be able to find the key by iteration

— If it's a function or method, just access .name (May be undefined if the function is anonymous)

— Sorry i am not understand

— 🤤

— Which part

— 'If it's a property AND you have access to the parent object'

— ?

— 

const obj = { prop: {} };
const { prop } = obj;

const nameOfProp = Object.entries(obj)
.find(x => x[1] === prop)[0];


If I want to find the key that was used for prop in obj, I would use this method, nameOfProp would then contain "prop"

Message permanent page

— Oh i see

— But if you just have:
const myVar = 4;

You can't get the name "myVar" out of it
(UNLESS it's a function)

Message permanent page

— 😱