3 回答
TA贡献1876条经验 获得超7个赞
在雇主的脑力激荡中,我的想法是:我将自己的工作推向正确的方向,如下所示:
function generateTable(a, b, c) {
document.write('<table cellspacing="5" cellpadding="1" border="1"><tr><th>State/Teritory</th><th>population</th><th>Growth Rate</th></tr>')
for (var i = 0; i < a.length; i++) {
document.write('<tr><td>' + a[i] + '</td><td>' + b[i] + '</td><td>' + c[i] + '</td></tr>');
}
document.write('</table><br><hr>');
}
TA贡献1793条经验 获得超6个赞
这应该给您您期望的结果:
const a = ['Hi', 'Hi', 'g', 'j', 'm', 'p', 's', 'v'];
const b = ['900', '900', 'h', 'k', 'n', 'q', 't', 'w'];
const c = ['654', '654', 'i', 'l', 'o', 'r', 'u', 'x'];
function exitToTable(a, b, c) {
let length = a.length;
if (length !== b.length || length !== c.length) {
console.warn('arrays must be of same length');
}
[...Array(length)].map((_, index) => {
document.write(`${[a[index], b[index], c[index]].join(' ')}<br/>`);
});
}
exitToTable(a, b, c);
TA贡献1810条经验 获得超4个赞
var arr_a = [],
arr_b = [],
arr_c = [];
for (var i = 0; i <= 7; i++) {
arr_a[i] = 'Hi';
arr_b[i] = 878;
arr_c[i] = 654;
}
exitToTable(arr_a, arr_b, arr_c);
function exitToTable(a, b, c) {
let tester = [];
tester[0] = [];
tester[0][0] = a[0];
tester[0][1] = b[0];
tester[0][2] = c[0];
tester[1] = [];
tester[1][0] = a[1];
tester[1][1] = b[1];
tester[1][2] = c[1];
tester[2] = [];
tester[2][0] = a[2];
tester[2][1] = b[2];
tester[2][2] = c[2];
tester[3] = [];
tester[3][0] = a[3];
tester[3][1] = b[3];
tester[3][2] = c[3];
tester[4] = [];
tester[4][0] = a[4];
tester[4][1] = b[4];
tester[4][2] = c[4];
tester[5] = [];
tester[5][0] = a[5];
tester[5][1] = b[5];
tester[5][2] = c[5];
tester[6] = [];
tester[6][0] = a[6];
tester[6][1] = b[6];
tester[6][2] = c[6];
tester[7] = [];
tester[7][0] = a[7];
tester[7][1] = b[7];
tester[7][2] = c[7];
for (var i = 0; i < 8; i++) {
for (var j = 0; j < 3; j++) {
//document.write(tester[i][j] + ' ');
}
//document.write('</br>');
}
console.log(tester);
console.log(tester[0][0]);
}
这是一个简单的示例,说明如何使用JavaScript创建多维数组
var array = [];
var array2 = [];
var array3 = [];
array2.push('text-1');
array2.push('text-2');
array3.push('item-1');
array3.push('item-2');
array.push(array2);
array.push(array3);
console.log(array);
console.log(array[0][1]);
找出数组的长度:array.length。
var array = [];
var array2 = [];
array2.push('text-1');
array2.push('text-2');
array[0] = array2;
console.log(array);
添加回答
举报