title: How to dynamically add values in JSON array using index
body: <p>I am having this format in my script</p>
  
  <pre><code>//declaration of JSON object
  items= {};
  items.values= [];
  </code></pre>
  
  <p>I need a structure like this, which is inserted automatically when the script is executed:</p>
  
  <pre><code>    items : 
          {
          key :['one', 'two', 'three', 'four'],
          values: [1, 2, 3, 4]
          }
  </code></pre>
  
  <p>Since the item.values[0] is undefined, it throws me a undefined error. Can anyone please tell me how to initialize the JSON object, such that it wont throw undefined error</p>
  
  <p>I would like to insert like this:</p>
  
  <pre><code>var i=0;
  item.key[i]= 'one';
  item.values[i]= 1;
  </code></pre>
  
  <p>I am not sure whether this is the best practice, if anyone knows better way please post it!</p>
  
  <p>Thanks in advance</p>