用字母序列填充固定的数组

时间:2019-07-08 15:15:40

标签: arrays object multidimensional-array

我有5个字母序列,循环中需要填充一个字母数组,如下所示。我要填充的数组 分配了16个数组。

如何以任何语言获得以下结果?

array =>
    0.["a"],
    1.["b"],
    2.["c"],
    3.["d"],
    4.["e"],
    5.["a"],
    6.["b"],
    7.["c"],
    8.["d"],
    9.["e"],
    10.["a"],
    11.["b"],
    12.["c"],
    13.["d"],
    14.["e"],
    15.["a"]

到目前为止,我已经使用Javascript创建了数组

var ArraySize = 16;

var arr = [];

for (var i = 0; i < ArraySize; i++) {
    arr.push(i);
    console.log("arr = " + arr[i] );
}

输出:

"arr = 0"
"arr = 1"
"arr = 2"
"arr = 3"
"arr = 4"
"arr = 5"
"arr = 6"
"arr = 7"
"arr = 8"
"arr = 9"
"arr = 10"
"arr = 11"
"arr = 12"
"arr = 13"
"arr = 14"
"arr = 15"

1 个答案:

答案 0 :(得分:1)

在javascript中:

var alphabet=['a','b','c','d'];
var arrayLimit =15;
var arr = [];
for (var i=0; i<arrayLimit; i++) 
   arr[i] = alphabet[i%alphabet.length];