I am trying use the value entered in an input as the name of the array I want to query.
This is my input:
<input id="enter" type="text">
This is what I have now.
$('#enter').on('keyup', function (e) {
var ex01 = ['up', 'down', 'left']
var ex02 = ['blue', 'green', 'red']
if (e.keyCode === 13) {
var matchingArray = 'ex' + ($(this).val());
var firstValue = matchingArray[0];
var secondValue = matchingArray[1];
console.log(firstValue);
console.log(secondValue);
}
});
My intent would be that if "01" is entered it would return the first and second values in ex01:
up
down
Instead I'm getting the first and second characters from the string "ex01".
e
x