title: Splicing an element in the middle of an associative array
body: <p>I want to add elements to arrays within an object that I access like this to retrieve data.</p>
  
  <pre><code>var event_id = events_data.event_id[i]["0"];
  var event_title = events_data.event_title[i]["0"];
  var selected_source = events_data.selected_source[i]["0"];
  var channel_id = events_data.channel_id[i]["0"];
  </code></pre>
  
  <p>events_data is an object with elements event_id, event_title, ... That object is created in a php function like this.</p>
  
  <pre><code>$return = array();
  $return['event_id'] = $event_id; 
  $return['event_title'] = $event_title;
  $return['selected_source'] = $selected_source;
  $return['channel_id'] = $channel_id;
  $return['channel_name'] = $channel_name;
  $return['event_site'] = $event_site;
  $return['event_url'] = $event_url;
  $return['start_date'] = $start_date;
  $return['start_time'] = $start_time;
  $return['end_date'] = $end_date;
  $return['end_time'] = $end_time;
  $return['event_notes'] = $event_notes;
  
  echo json_encode($return);
  </code></pre>
  
  <p><strong>EDIT - ADDED INFO</strong></p>
  
  <p>The json object looks like this.</p>
  
  <p>{"event_id":[{"0":"e20120319215556"},{"0":"e20120310221512"},{"0":"e20120319151903"},{"0":"e20120309123705"},{"0":"e20120307122044"},{"0":"e20120306182514"},{"0":"e20120309211714"},{"0":"e20120314130727"},{"0":"e20120319150532"},{"0":"e20120319141928"},{"0":"e20120319141201"},{"0":"e20120301193226"},{"0":"e20120301184354"}]}</p>
  
  <p><strong>END INFO ADDED</strong></p>
  
  <p>On the javascript side I get the events_data array like this.</p>
  
  <pre><code>$.ajax({
      url: "get_events_data.php",
      type: "POST",
      dataType : 'json',
      data: { },
      cache: false,
      async: false,
      success: function (rdata) {
          events_data = rdata;
                    }
           });
  </code></pre>
  
  <p>To add an element to events_data on the javascript side, I check for the index where to add the new element and then add it with splice. But since the data is retrieved with the ["0"] text key for the associative array, I don't know how to specify the splice parameters.</p>
  
  <pre><code>for ( var n=0; n&lt;events_data.event_id.length; n++ ) { 
     if ( current_event_id == events_data.event_id[n]["0"] ) {
         //splice_index = n;              
         events_data.event_id.splice(n,0,event_id);
         events_data.event_title.splice(n,0,event_title);
         events_data.selected_source.splice(n,0,selected_source);
         events_data.channel_id.splice(n,0,channel_id);
         events_data.channel_name.splice(n,0,channel_text);
         events_data.event_site.splice(n,0,event_site);
         events_data.event_url.splice(n,0,event_url);
         events_data.start_date.splice(n,0,start_date_string);
         events_data.start_time.splice(n,0,start_time_string);
         events_data.end_date.splice(n,0,end_date_string);
         events_data.end_time.splice(n,0,end_time_string);
         events_data.event_notes.splice(n,0,event_notes);
         break;
      }
  }
  </code></pre>
  
  <p>Specifying the splice index "n" doesn't seem to do it. What should I change?</p>
  
  <p>Thanks.</p>