我有幾個數組:如何檢索數組中的值以使用jQuery從其他數組獲取值?
cl = ["Chile", "15", "83"];
ar = ["Argentinia", "16.5", "90"];
py = ["Paraguay", "19", "81.5"];
route = ["cl;ar", "ar;py"];
是否可以遍歷一個數組,並從其他陣列獲取的特定值? 我已經試過這沒有工作:
$.each(route, function(index,value) {
place = v.split(';');
start = place[0];
end = place[1];
console.log('from '+start[0]+' to '+end[0]);
});
日誌中應顯示:"from Chile to Argentinia", "from Argentinia to Paraguay"
但它把剛"from c to a", "from a to p"
。
我錯了什麼,我怎麼讀取其他數組的值?
使用eval(end +' [0]') – Matt
謝謝你馬特! eval(...)完美地工作。 – user2402747