title: Unnexpected output in js sort function
body: <p>guys I am trying to sort an array  but I have a little problem, the sorting starts but 
  one of the elements is marked as undefined and I can't  figure out why. In general I am not sure whether I call the function the right way. Please help me! :)</p>
  
  <p>that's the code:</p>
  
  <pre><code>&lt;p&gt;JavaScript can change the content of an HTML element.&lt;/p&gt;
  &lt;button type="button" onclick="myFunction()"&gt;Click Me First!&lt;/button&gt;
  
  &lt;div id="demoto0"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto1"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto2"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto3"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto4"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto5"&gt;This is gonna be changed &lt;/div&gt;
  &lt;p&gt; ---------------------------------------- &lt;/p&gt;
  &lt;div id="demoto+0"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto+1"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto+2"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto+3"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto+4"&gt;This is gonna be changed &lt;/div&gt;
  &lt;div id="demoto+5"&gt;This is gonna be changed &lt;/div&gt;
  &lt;p id="flag"&gt; false &lt;/p&gt;
  &lt;script&gt;
  var arr = [1,2300, 94000, 34, 280, 294];
  function selectionsort(cont){
      var ns = cont.ns;
      var n = cont.length;
  
      var n = arr.length;
      //var n = 6;
      for(var i=0; i&lt;n-1; ++i)
      {
          var index = i; // markirame na4alna strelka ^
          for(var j=i+1; j&lt;n; ++j)
          {
              // markirame sys strelki vseki element
              if(arr[index] &gt; arr[j])
              {
                  index = j;  
              }
          } 
          if(i != index)
          {
              var temp = arr[j];
              arr[j] = arr[index];
              arr[index] = temp;
          }
      }
  
      document.getElementById("flag").innerHTML = "Hello JavaScript!";
  
  }
  
  function myFunction() { 
      //var arr = [1,2300, 94000, 34, 280, 294];
      document.getElementById("demoto1").innerHTML = "Hello JavaScript!";
      document.getElementById("demoto0").innerHTML = arr[0];
      document.getElementById("demoto1").innerHTML = arr[1];
      document.getElementById("demoto2").innerHTML = arr[2];
      document.getElementById("demoto3").innerHTML = arr[3];
      document.getElementById("demoto4").innerHTML = arr[4];
      document.getElementById("demoto5").innerHTML = arr[5];
  
      //arr.sort(function(a,b){return a-b;});
      selectionsort(arr);
  
      document.getElementById("demoto+0").innerHTML = arr[0];
      document.getElementById("demoto+1").innerHTML = arr[1];
      document.getElementById("demoto+2").innerHTML = arr[2];
      document.getElementById("demoto+3").innerHTML = arr[3];
      document.getElementById("demoto+4").innerHTML = arr[4];
      document.getElementById("demoto+5").innerHTML = arr[5]; 
  }
  &lt;/script&gt;
  </code></pre>