这是我的代码:
if(notas_insert[selected_n_document] === "undefined"){
notas_insert[selected_n_document] = [];
}
if(notas_insert[selected_n_document][selected_version] === "undefined"){
notas_insert[selected_n_document][selected_version] = [];
}
if(notas_insert[selected_n_document][selected_version]["index"] === "undefined"){
notas_insert[selected_n_document][selected_version]["index"] = 0;
}
notas_insert[selected_n_document][selected_version][notas_insert[selected_n_document][selected_version]["index"]] = notas_pre;
notas_insert[selected_n_document][selected_version]["index"]++;
我得到这个错误:
Cannot read property '1' of undefined
我如何用代码在数组中创建数组,因为如果我在控制台中写:
notas_insert[selected_n_document] = [];
我不再在第三行看到错误,但由于某种原因,如果我在代码中这样做,它似乎就不起作用了。
像这个一样检查您的状况
if(typeof notas_insert[selected_n_document][selected_version] === "undefined")
我会用这样的东西设置默认值:
var doc = notas_insert[selected_n_document] || [];
var version = doc[selected_version] || [];
etc