0

I need to convert a function argument name into string.

const newFn = 'something';
const transformVarName = (variable) => {
  return Object.keys({variable});
  };
  
  console.log(transformVarName(newFn)) // Should return 'newFn', not 'variable'
  • Function should return the name of the variable that I use as argument in this function. – Cherniugov Yevgenii Jun 14 '22 at 14:40
  • 2
    That is not possible. A variable name is not a string. Related answer here: https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically/32108558#32108558 – Domino Jun 14 '22 at 14:41

1 Answers1

0

Try this

return Object.keys({newFn})[0]
Isaac Jandalala
  • 308
  • 3
  • 9