[英]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.