繁体   English   中英

如何找到一个数组的索引并将该索引值用于另一个数组中的 select 值

[英]How to find the index of one array and using that index value to select value from another array

const COUNTY = ["DELHI","GUJARAT","GOA","ANDHRA"]

const COUNTY_CODE = ["001","002","003","004"]

我们有 2 个 arrays。第一个数组,我们在下拉列表中显示。 我们需要根据第一个数组中选择的县从第二个数组传递县代码。

如何使用 angular JS 和 javascript 和 typescript 来做到这一点?

您可以使用indexOf function 来查找县的索引,然后使用它来查找第二个数组中的代码。

 const COUNTY = ["DELHI","GUJARAT","GOA","ANDHRA"] const COUNTY_CODE = ["001","002","003","004"] const selected = "DELHI"; const selectedIndex = COUNTY.indexOf(selected); const code = COUNTY_CODE[selectedIndex]; console.log(code);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM