title: Elements are getting omitted from Javascript array - problem
body: <p>I want to sort an array from lowest number to highest. But when I execute the following code, some of my array elements get missed! I don't know why. I need help.`// Sort an array from lowest to highest</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function findSmallest(numArr) {
    let smallestNumber = numArr[0]
  
    for (let i = 0; i &lt; numArr.length; i++) {
      if (numArr[i + 1] &lt; smallestNumber) {
        smallestNumber = numArr[i + 1]
      }
    }
    return smallestNumber;
  }
  
  function getSortedArray(arr) {
    let sortedArray = []
  
  
    for (j = 0; j &lt; arr.length; j++) {
      let smallest = findSmallest(arr)
      let smallestNumbmerIndex;
  
      for (let i = 0; i &lt; arr.length; i++) {
        if (arr[i] === smallest) {
          smallestNumbmerIndex = i
        }
      }
      arr.splice(smallestNumbmerIndex, 1)
      sortedArray.push(smallest)
    }
  
    return sortedArray
  }
  
  let myArr = [23, 2, 12, 4]
  console.log(getSortedArray(myArr)) // console output =&gt; [2, 4] , the rest elements get omitted</code></pre>
  </div>
  </div>
  </p>