This is a sample from my java script code. With this code I get a correct result (1, 2). Now, instead variable "james" I want to set a variable depending on input value (var input in this case). How can I do that? Is there a way to find JavaScript variable on the page via input value?
var james = "James",
daniel = "Daniel",
jacob = "Jacob";
// some code //
var james = [1, 2],
daniel = [3],
jacob = [4, 5];
function buttonclick()
{
var input = document.getElementById("selector").value;
var text2 = "";
var y;
for (y in james) {
text2 += james[y] + "<br>";
}
document.getElementById("demo").innerHTML = text2;
}