I want to get the name of constant :
const MY_CONSTANT = 1;
I want to show the name of my constant (MY_CONSTANT) not value (1).
I want to get the name of constant :
const MY_CONSTANT = 1;
I want to show the name of my constant (MY_CONSTANT) not value (1).
You cannot get the name of the constant or a variable in JavaScript. The closest thing to what you want to do would be setting a property inside an object. Then, you can get the names of all keys.
var obj = { myFirstName: 'John' };
obj.foo = 'Another name';
for(key in obj)
alert(key + ': ' + obj[key]);
See karim79's answer here