I have several arrays that I json_encode form php and two variables that I get from an inputs, lets say :
let a = [1,2,3,4,5];
let b = [1,2,3,4,5];
let c = [1,2,3,4,5];
let d = [1,2,3,4,5];
let e = [1,2,3,4,5];
let f = [1,2,3,4,5];
let name = document.getElementById("some_element").value
let number = document.getElementById("some_other_element").value
I wanna check if the name is the same as the array name and then use the array with the name for example a[number].
I am not quite sure of how to do this. Any help would be really welcome.
Use an object:
const arrays = {
a: [1, 2, 3, 4, 5],
b: [1, 2, 3, 4, 5],
c: [1, 2, 3, 4, 5],
d: [1, 2, 3, 4, 5],
e: [1, 2, 3, 4, 5],
f: [1, 2, 3, 4, 5],
};
const name = "a";
const number = 1;
console.log(arrays[name][number]);