user517406 user517406 - 5 months ago 7
Javascript Question

creating list of objects in Javascript

Is it possible to do create a list of your own objects in Javascript? This is the type of data I want to store :

Date : 12/1/2011
Reading : 3
ID : 20055

Date : 13/1/2011
Reading : 5
ID : 20053

Date : 14/1/2011
Reading : 6
ID : 45652

Answer
var list = [
    { date: '12/1/2011', reading: 3, id: 20055 },
    { date: '13/1/2011', reading: 5, id: 20053 },
    { date: '14/1/2011', reading: 6, id: 45652 }
];

and then access it:

alert(list[1].date);