variable name to string javascript

//Get variable name as string
function getVariableName(v) {
    for (var key in window) {
        if (window[key] === v)
            return key;
    }
}

//testing
var someValue = "something not important right now";
console.log(getVariableName(someValue)); //>> prints "someValue"
//also works in functions
function print(a) {
  console.log(getVariableName(a)); //>> prints "someValue" because of line 16
  //you'd think it would print "a" but it doesnt
}
print(someValue);//>> look at line 14

3.71
7
Awgiedawgie 440220 points

                                    var a = [1, 3, 4, 3]
var b = [1, 5, 6, 7]
var c = [3, 4, 8, 9]

function arraySum(x, varName) {
    var sum = 0
    for (let i = 0; i < x.length; i++) {
        sum += x[i]
    }
    console.log("sum of " + varName + " is " + sum)
}

arraySum(a, "a");

3.71 (7 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
js use variable name as string how can we use variable name as text in js how to get the string name of a variable in javascript how to name a javascript variable Convert string to variable name in JavaScript get the name of variable javascript as string javascript use variable name as string javascript string as variable name convert string to variable name javascript how to convert a string to a variable name in javascript get variable name as a string js variable function name in javascript convert string to variable name js js name variable function js variable name as string javascript get variable name string how to get variable name as string javascript get name of variable as string javascript how to attach variable name to string in javascript js how to use string variable as function name return variable that with name of string js convert a string to variable name javascript var name inside a string js how to get variable name string js javascript change string to variable name variable function name js javascript function with variable name why can i name a variable name in javascript how to get variable name as string in javascript how to convert a string to normal variable name in javascript node js string to variable name variable name is a string value in js var name in javascript return a variable name as a string javascript how to store variable name as string javascript javascript variable name $ how to use % in a variable name javascript variable name to string javascritp return variable name as string js # as variable name in js use variable name as string js js variable name string javascript variable function name convert string into variable name javascript convert string value to variable name javascript javascript text variable function name variable name string javascript how to make var name from string in js js convert string to variable name the name of the variable as string javascript variable name in js javascript get name of variable in function as string javascript get name of variable as string js variable in function name js string in variable name variable with "name" in javascript variable with name in javascript javascript variable variable name how to convert string to variable name in javascript javascript variable name to string javascript set variable name from string javascript convert variable name to string javascript convert a string to a variable name how to make javascript variable name javascript get variable name as string get varible name string js string to var name javascript string to var name in js js var name from string js variable name from string javascript convert name to string how to make a string a variable name javascript string to variable name javascript pass variable name as string in js set variable data from string var name js javascript set string as variable name javascript string to variable name javascript name variable name variable in javascript convert variable name to string javascript using string as a variable name in javascript how to convert variable name to string in javascript javascript pass variable name as string node.js make variable with string as name variable name to string javascript javascript create function with variable name node js variable name from string javascript function name variable how to parameter to be name of variable javascript javascript function param variable name as string javascript function param variable name as in string javascript variable name as string javascript name of variable as string javascript set variable by string name variable in name js pass variable name as string and get that variable javascript variable name from variable javascript how to create function with variable name in js js get string as var name Variable name as string JavaScript get variable name as string js how to make a varianle name from a string in js javascript use a string as a variable name how to turn variable name into string javascript name of a variable as a string js have a string call a variable name, js return the name of the var as string javascript create variable name from string js using string as variable name in js {$ } using string as variable name in js js create variable name from string use string as variable name javascript ${variable Name}& name in javascript can i use $ as variable name in javascript can i use as variable name in javascript javascript pass string as variable name js variable name to string nodejs make a variable name a string javascript variable in a name string javascript var name = function javascript create variable name from string create a variable name from a string javascript javascript get a variable name as a string use string as a variable name javascript define a variable name with a string nodejs define a variable name with a string javascript js get name of variable create a variable with string name javascript how to print the variable name along with it's value in javascript how to print the variable name in javascript turn variable name into string javascript how to convert variable name to string in JS call var name by string get name of variable javascript javascript get name of variable use msg value or variable as key javascript javascript, get name of variable as string js access variable name using string referance how to print variable name in javascript node log variable name get string from variable name js javascript get Variable name js string as function name how to use variable name as string javascript how to access the name of a variable javascrip javascript name in string javascript get variable with string name javascript nameof variable how to have & in variable name js js get var name as string get variable name in javascript javascript $_GET["name"] js variable as different name get variable by string name javascipt nodejs print variable name and value get variable name javascript use variable name from string how to get store variable name in js using string to name variable javascript js var name = {} javascript print variable name get the variable name in js js make function name string js print variable name as string get var name js get variable name as string javascript get string of variable name javascript javascript name of variable get name of variable Js javascript how o make name of string var variable name as a string in Javascript function
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source