Print / display a JavaScript variable's name instead of it's value

前端 未结 3 1156
一整个雨季
一整个雨季 2020-12-01 18:53

Is it possible to print / display a JavaScript variable\'s name? For example:

var foo=5;
var bar=6;
var foobar=foo+bar;

document.write(foo+ \"
\");
3条回答
  •  日久生厌
    2020-12-01 19:20

    Another possible solution can be "Object.keys(this)".... This will give you all the variable names in an array.

提交回复
热议问题