How to turn variable name into string in JS?
问题 I am trying to write a convenience wrapper for console.log, and I would like to print any variables passed in along with their contents. Can I turn a variable name into a string in js? 回答1: Assuming you want something like this: function Log(data) { console.log(input variable name, data); } Then I don't think it is possible: For convenience.. you could do something like console.log({ "your variable name": your variable}); Which turns the input to an object that does contain the variable name