Arrays 未捕获的TypeError:无法读取未定义的属性“pcId”

Arrays 未捕获的TypeError:无法读取未定义的属性“pcId”,arrays,Arrays,我是一个新的JS,我正在接收JSON上的数据,稍后我必须解析这些信息。我必须填充一个数组,但是我得到了这个错误uncaughttypeerror:当我试图捕获信息时,无法读取undefined的属性“pcId” function getDataBase(data){ console.log(data); var arrEmployee = []; var length = data.ttPerson.length; console.log(data.ttP

我是一个新的JS,我正在接收JSON上的数据,稍后我必须解析这些信息。我必须填充一个数组,但是我得到了这个错误uncaughttypeerror:当我试图捕获信息时,无法读取undefined的属性“pcId”

function getDataBase(data){  
    console.log(data);
    var arrEmployee = [];
    var length = data.ttPerson.length;  
    console.log(data.ttPerson[0].pcId)
    for(var index = 0; index<= length; index++){
        console.log(data.ttPerson[index].pcId);
        var pcId = data.ttPerson[index].pcId;
        console.log(pcId);
    }; 
    var customerDataDB = [
        { id: arrEmployee[0], name: arrEmployee[0], picprofile:"", number:"345", subject:"Ingles", classroom: "23", build:"2", group:"17", sign:"", picture:"", ready:false, sent:false},     
        { id: arrEmployee[1], name: arrEmployee[1], picprofile:"", number:"345", subject:"Ingles", classroom: "23", build:"2", group:"17", sign:"", picture:"", ready:false, sent:false}
    ]; 
}
我想在ArEmployee中设置数据值,或者可以构建一个数组来传递给DB


谢谢

如果出现该错误,那是因为您试图在不存在的未定义对象上获取pcId属性。我从您的代码中发现的问题可能是:

console.logdata.ttPerson[0].pcId

这里缺少一个分号,但更重要的是,如何确保array data.ttPerson的大小不是零?如果尝试在空数组上调用data.ttPerson[0],则使用的是未定义的对象


forvar指数=0;我明白,问题是名为data的对象实际上内部有两个数组。是ttError和ttPerson,每次调用console.log时,控制台输出都会显示变量的内容,下面显示错误。我已经有了确保对象包含数据的方法: