Get variable names with JavaScript

前端 未结 7 963
傲寒
傲寒 2021-02-08 18:47

I want to create a log function where I can insert variable names like this:

var a = \'123\',
    b = \'abc\';

log([a, b]);

And the result sho

7条回答
  •  野的像风
    2021-02-08 19:18

    I had a somewhat similar problem, but for different reasons.

    The best solution I could find was:

    MyArray = ["zero","one","two","three","four","five"]; 
    MyArray.name="MyArray";
    

    So if:

    x=MyArray.name;
    

    Then:

    X=="MyArray"
    

    Like I said, it suited my needs, but not sure HOW this will work for you. I feel silly that I even needed it, but I did.

提交回复
热议问题