请参考这个:
http://jsfiddle.net/MasterOfKitties/v7xbu/7/
/*This is the desired behavior*/
/*var A = [1, 2, 3]*/
/*var B = "hello", [1, 2, 3],
"hello", [2, 3, 2],
"hello", [1, 5, 1]]*/
var A = new Array();
var B = new Array();
function fnMakeArray()
{
var strTemp;
var arrTemp = new Array();
strTemp = parseInt(window.prompt("Enter a number until you hit cancel",""));
while (strTemp>0)
{
arrTemp.push(strTemp);
strTemp = parseInt(window.prompt("Enter a number until you hit cancel",""));
}
A[0] = "hello";
A[1] = arrTemp;
alert(A);
}
function fnReplicateArray()
{
B.push(A);
fnDisBArray();
alert(B);
}
function fnDisBArray()
{
var strTemp;
for(var x = 0; x<B.length;x++)
{
strTemp += "<P>" + B[x] + "</p>"
}
document.getElementById('parse').innerHTML = strTemp ;
}
出于某种原因,当尝试显示 B 数组时,它会显示未定义。此外,它似乎没有正确地增加锯齿状数组,因为即使 b[1] 或 b[2] 元素正在排列,b[0] 元素也开始发生根本变化。
有什么帮助吗?这是怎么回事?