function arrinp() {
var ar1 = [];
for(i=0;i<3;i++){
for(j=0;j<3;j++){
prompt(ar1.push(ar1[i][j]));
}
}
}
arrinp();
答案 0 :(得分:0)
当然,替换
prompt(ar1.push(ar1[i][j]));
与
ar1[i][j] = prompt("Enter value");
完整代码
function arrinp() {
var ar1 = [];
for (i = 0; i < 3; i++) {
ar1[i] = []; //observe this line as well
for (j = 0; j < 3; j++) {
ar1[i][j] = prompt("Enter value");
}
}
return ar1; //return the array
}
console.log(arrinp());
<强>演示强>
function arrinp() {
var ar1 = [];
for (i = 0; i < 3; i++) {
ar1[i] = []; //observe this line as well
for (j = 0; j < 3; j++) {
ar1[i][j] = prompt("Enter value");
}
}
return ar1; //return the array
}
console.log(arrinp());