Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从对象数组中获取数据_Javascript - Fatal编程技术网

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

我不知道如何从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 = 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
。Do
dataset[0]。fk_idPers
您可能想了解如何操作。是的,谢谢,我会看一看:)哦,谢谢,它是对的,它可以工作。我现在觉得有点愚蠢:/@Ishiru-不用担心。学习时,每个人都应该思考和提问:)