Array of Objects

var questions = [
  {
    question: 'How many states are in the United States?', 
    answer: 50
  },
  {
    question: 'How many continents are there?',
    answer: 7
  },
  {
    question: 'How many legs does an insect have?', 
    answer: 6
  }
];

OR

var questions = [
  { question: 'How many states are in the United States?', answer: 50 },
  { question: 'How many continents are there?', answer: 7  },
  { question: 'How many legs does an insect have?', answer: 6  }
];

JSON – JavaScript Object Notation

Because JavaScript objects provide a structured way to store data, JavaScript objects are used to transfer information between browsers, servers, databases and other online services.

Because of that, objects have become the model for one of the most popular data exchange formats on the web, JSON – JavaScript Object Notation.

{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}

AJAX & JSON Example

JSON is commonly used with AJAX to exchange data between a server and the browser.

Using AJAX, a browser can ask for a list of recent photos uploaded to the Flickr website. The information for those images is sent in JSON format, which can easily be converted to a JavaScript object and used to display those images on a webpage.

Important Note: JSON is formatted LIKE a JavaScript object literal, but it’s really just a string of characters. Once that string is received by the browser, it can convert it into a JavaScript object.