[英]Kind of increment on arrays in js
我想對數字進行網格計算,網格為30x30,所以我想到了30個包含30個數字的數組的想法。 現在我正在尋找一種以簡單的增量從array1轉到array2的方法,而不是重新鍵入30次
var array1 = ['blue','red'];
var array2 = ['magenta','yellow'];
var curarray = 1;
console.log(array+curarray)
//something like the above (the example obviously doesn't work)
只需創建一個包含所有數組的數組
var arr = [
['blue','red'],
['magenta','yellow']
];
然后,您可以通過其索引訪問數據(數組自動具有索引)
var curarray = 0;
console.log(arr[curarray]); // ['blue','red']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.