title: insert item in javascript array and sort
body: <p>Let's say I have an array</p>
  
  <pre><code>var test = new Array()
  </code></pre>
  
  <p>the values in test are 3,6,9,11,20</p>
  
  <p>if I then have a variable</p>
  
  <pre><code>var id = 5
  </code></pre>
  
  <p>how can I insert 5 between 3 and 6 in the array?
  or do I just insert it wherever and then sort the array?</p>
  
  <p>Thanks in advance.</p>
  
  <p>edit:</p>
  
  <p>I have the following code:</p>
  
  <pre><code>function gup( filter )
  {
    filter = filter.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&amp;]"+filter+"=([^&amp;#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
      return "";
    else
      return results[1];
  }
  
  var queryString = gup("SelectedID");
  
  
  var hrefs = new Array();
  $('.table404').children().children().each(function(){
  var link = ($(this).find('a').attr('href'));
  var startIndex = link.indexOf(",'");
  var endIndex = link.indexOf("');");
  if ( startIndex &gt;= 0 &amp;&amp; endIndex &gt;= 0 ) {
  var linkID = link.substring( startIndex+2, endIndex );
  hrefs.push(linkID);
  hrefs.push(queryString);
  hrefs.sort()
  }
  alert(hrefs);
  });
  </code></pre>
  
  <p>for each item inserted into the array I get an alert with the ID but for every item I get one 1 (the current queryString value), so the last pop up looks something like
  1,1,1,1,1,2,4,6,7,8</p>
  
  <p>Why do I get a new pop up for every item inserted into the array? I get the querystring value once for every other item inserted into the array. What do I have to do to get one pop up with the complete array?</p>