Ad

Defining A Multidimensional Object In Javascript

I have some data on cars and am trying to create a function where I can get info on a specific car. I can't seem to format my data list correctly. I run it through JSLint and it tells me it is wrong but I don't know how to fix it.

var models = {
  "2009": 
    {Jaguar: [model: "XF", id: "123"], [model: "XK", id: "456"], [model: "XJ", id: "789"]}, 
    {Volvo: [model: "XC70", id: "223"], [model: "V50", id: "256"]}, 
  "2010": 
    {Jaguar: [model: "XF", id: "323"], [model: "XK", id: "356"]}, 
    {Volvo: [model: "XC70", id: "423"], [model: "V50", id: "456"]}
  };
   //**** Show an example model here
    console.log(models.2010.Jaguar[0].model);
Ad

Answer

You could change to something like this:

var models = {
    "2009":
            {
                Jaguar: [{model: "XF", id: "123"}, {model: "XK", id: "456"}, {model: "XJ", id: "789"}],
                Volvo: [{model: "XC70", id: "223"}, {model: "V50", id: "256"}]
            },
    "2010":
            {
                Jaguar: [{model: "XF", id: "323"}, {model: "XK", id: "356"}],
                Volvo: [{model: "XC70", id: "423"}, {model: "V50", id: "456"}]
            }
};
//**** Show an example model here
console.log(models['2010'].Jaguar[0].model);
Ad
source: stackoverflow.com
Ad