2d-arrays 中文文档教程
2d-Array
在 JavaScript 中创建完美的二维数组,而无需为其编写自定义 js
。
let dArray = require("2d-arrays");
let x = dArray(2, 2, true);
// [[0,0],
// [0,1]]
dArray(arg1, arg2, arg3)
arg1 代表 n 行数,arg2 代表 m 列数。 arg3 是可选参数。
Cases for arg3
// Case I - To initilize every element to undefined (by default)
dArray(4, 2);
// Output
[
[undefined, undefined],
[undefined, undefined],
[undefined, undefined],
[undefined, undefined],
];
// Case I - To initialize with index position the index numbers
dArray(4, 2, true);
// Output
[
["0,0", "0,1"],
["1,0", "1,1"],
["2,0", "2,1"],
["3,0", "3,1"],
];
// To initilize every element to null
dArray(4, 2, true);
// Output
[
[null, null],
[null, null],
[null, null],
[null, null],
];
2d-Array
Create perfect 2d arrays in JavaScript without writing a custom js
for it.
let dArray = require("2d-arrays");
let x = dArray(2, 2, true);
// [[0,0],
// [0,1]]
dArray(arg1, arg2, arg3)
arg1 represents the n number of rows and arg2 represents the m numbers of coloumns. arg3 is an optional arguments.
Cases for arg3
// Case I - To initilize every element to undefined (by default)
dArray(4, 2);
// Output
[
[undefined, undefined],
[undefined, undefined],
[undefined, undefined],
[undefined, undefined],
];
// Case I - To initialize with index position the index numbers
dArray(4, 2, true);
// Output
[
["0,0", "0,1"],
["1,0", "1,1"],
["2,0", "2,1"],
["3,0", "3,1"],
];
// To initilize every element to null
dArray(4, 2, true);
// Output
[
[null, null],
[null, null],
[null, null],
[null, null],
];