0

How to pass funtion's argument's name as string into nested function? I have 2 variables, let's say name1=5 and name2=10, i wanted to make a function that would use one of those variables values and in other place use the variable's name as string.

var name1 = 5
var name2 = 10

function func(arg){
    document.getElementById("a1").innerText = arg //that works fine, it sets the text as 5 or 10
    document.getElementById("arg" + "some string").innerText = "some other string" // here i need the argument's name as string, for example "name1".
}

I hope that my question is understandable, english is not my default language.

bukszpryt
  • 23
  • 3
  • Closing someone's question after linking assumed related question is a bad idea. Linked solution doesn't apply here in my opinion. I don't want to reference variable, by it's name in string, but quite the opposite. I have variable and i want to get a string of it's name, so if it var foo="abc", what i need is "foo", not variable called abc. – bukszpryt Mar 21 '21 at 18:37
  • If you're looking for an answer for that problem, it is here: https://stackoverflow.com/questions/47468361/get-variable-name-into-string-in-javascript/47468674 – bukszpryt Mar 21 '21 at 20:23

0 Answers0