Javascript 从对象数组中获取数据
我不知道如何从Javascript中充满对象的数组中获取数据。以下是我的代码和错误消息:Javascript 从对象数组中获取数据,javascript,Javascript,我不知道如何从Javascript中充满对象的数组中获取数据。以下是我的代码和错误消息: //First I create the table var dataset = []; //Then I declare the object var PersReunionObj = {}; //Now I throw some data into the object PersReunionObj.fk_idPers = fk_idPers; PersReunionObj.fk_idReunion
//First I create the table
var dataset = [];
//Then I declare the object
var PersReunionObj = {};
//Now I throw some data into the object
PersReunionObj.fk_idPers = fk_idPers;
PersReunionObj.fk_idReunion = fk_idReunion;
PersReunionObj.isPresent = isPresent;
//I insert the object into a table
dataset[0] = PersReunionObj;
现在我想从我的表中获取这些数据
console.log(dataset[0]);
给我:
{fk_idPers:1,fk_idReunion:1,isPresent:true}
所以我的桌子没问题。但为了获取数据,我尝试了以下方法
console.log(dataset[0].PersReunionObj.fk_idPers);
这给了我一个错误:
未捕获的TypeError:无法读取未定义的属性“fk_idPers”
我如何解决这个问题?您只需要调用,因为
dataset[0]
是PersReunionObj
console.log(dataset[0].fk_idPers);
dataset[0]=PersReunionObj
因此dataset[0]
是PersReunionObj
。Dodataset[0]。fk_idPers
您可能想了解如何操作。是的,谢谢,我会看一看:)哦,谢谢,它是对的,它可以工作。我现在觉得有点愚蠢:/@Ishiru-不用担心。学习时,每个人都应该思考和提问:)