1

I don't get how to get data from an array filled with objects in Javascript. Here is my code and error message :

//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;

Now I would like to get back those data from my table

console.log(dataset[0]);

Gives me :

{fk_idPers: 1, fk_idReunion: 1, isPresent: true}

So my table is OK. But then to get data, i tried something like

console.log(dataset[0].PersReunionObj.fk_idPers);

And it gives me an error :

Uncaught TypeError: Cannot read property 'fk_idPers' of undefined

How can i fix that ?

Ishiru
  • 127
  • 1
  • 16

1 Answers1

3

You simply need to call because dataset[0] is PersReunionObj

console.log(dataset[0].fk_idPers);
Nikhil Aggarwal
  • 28,197
  • 4
  • 43
  • 59