Jquery多维数组:无法转换未定义的对象



我试图用自动增量(listeFormatte.lenght)填充数组,但它在listeFormatte[listeFormatte.length][0] = cartArray[i][0];行中断,并给出无法转换未定义对象的错误。

cartArray[i][0] = "ensemble"
listeFormatte = "" (new array)
listeFormatte.length = 0

提前谢谢。

var listeFormatte = new Array;
for(var i=0;i<cartArray.length;i++)
{
    if(cartArray[i][0] == "ensemble")
    {
        listeFormatte[listeFormatte.length] = [];
        listeFormatte[listeFormatte.length][0] = cartArray[i][0];
    }
}

编辑:什么是imagemagick转换?它与我正在做的事情无关,你为什么要用这样的东西编辑我的东西?

答:所以当listeFormatte[listeFormatte.length]=[]时;创建多维数组,它引发listeFormatte.lenght,这导致在"第二次使用"时未定义,因为它现在是:listeFormatte[1]而不是[0]。所以我添加了一个变量,它得到listeFormatte.length.

您考虑过吗listeFormatte[listeFormatte.length] = new Array;

我以前从未见过listeFormatte[listeFormatte.length] = [];构造,如果没有类似的东西,你的listeFormatte[listeFormatte.length]就不会被定义为数组,所以你不能使用[0]索引。

最新更新