jquery - jQuery:使用输入的值作为匹配数组的名称
问题描述
我正在尝试使用输入中输入的值作为我要查询的数组的名称。
这是我的输入:
<input id="enter" type="text">
这就是我现在所拥有的。
$('#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);
}
});
我的意图是,如果输入“01”,它将返回 ex01 中的第一个和第二个值:
up
down
相反,我从字符串“ex01”中获取第一个和第二个字符。
e
x
解决方案
推荐阅读
- azure - 如何在 Azure DevOps YAML 条件中使用数组
- docker - 如何在 Elastic Beanstalk Docker 环境中使用主机公开 docker 端口?
- kotlin - Retrofit2 为什么 Flow 没有 CallAdapterFactory
- pandas - Pandas 中两个日期列的差异
- loops - 循环树枝对象
- c++ - Plus operator on strings in c++
- hibernate - Hibernate Session Factory 的创建成本很高
- oracle - 如果第一个条件匹配,PLSQL 过程返回真
- reactjs - redux更新后如何更新useRef
- java - 如何在 Spring Boot 应用程序中执行“pg_advisory_lock”?