0

I want to pass a 2 dimensional array:

events = [
    {
        title: 'All Day Event',
        start: '2014-09-01'
    },
    {
        title: 'Long Event',
        start: '2014-09-07',
        end: '2014-09-10'
    }
];

to a display function:

function display(events){
    alert(display the matrix);
};

but it doesn't work, it displays just "objects" and not the value of the objects

Lexi
  • 1,670
  • 1
  • 19
  • 35
Wissem Achour
  • 177
  • 1
  • 3
  • 13

2 Answers2

0

In your display function just iterate over the elements in events.

Your function has to look somewhat like the following:

function display(e){
    for(i=0; i < e.length; i++){
    // do stuff, e.g.:
        alert(e[i]["title"]);
    }
}

Call it like this:

display(myEvents);

where "myEvents" is your two dimensional array.

FlixMa
  • 944
  • 1
  • 7
  • 20
0

You first need to loop through your array. Your array contains objects so you need a second loop to access the properties of the objects.

jsfiddle demo

function display(ar){
    for(var i=0;i<ar.length;i++){//loop through array ar
        for(k in ar[i]){//loop through the properties of each object
            console.log(k+': '+ar[i][k]) //output too JS console (press F12)
        }
    }

};
kasper Taeymans
  • 6,950
  • 5
  • 32
  • 51