title: JavaScript: How to sort data got from Firebase and show only part of them?
body: <p>I've tried create some function which could sort data from Firebase by highest score value and show only top 5. Now I can easily get and show on the web all data in appearing order, which is not very useful for me.</p>
  
  <p>Function <code>gotData</code> give me proper format of data from Firebase and put every score in li element on the list.</p>
  
  <pre><code>console.log(JSON.stringify(scores)) print 
  
  {"-KYxmoU7NnbTk0EpURZO":{"initials":"Rafi","score":8},
  "-KYxnLZ0HyftwOENmTs1":{"initials":"Wichru","score":13},
  "-KYxndQcCmiRDet-kLlK":{"initials":"Meg","score":36},
  "-KYxpnFkihQhung3_1s_":{"initials":"asas","score":0},
  "-KZ0I4eeAvReZdlw-9dL":{"initials":"Ryan","score":28}}
  </code></pre>
  
  <p>I also did:</p>
  
  <pre><code>var values = Object.values(scores);
  values.sort( (a, b) =&gt; b.score - a.score );
  </code></pre>
  
  <ul>
  <li>as you said</li>
  </ul>
  
  <p>and object is sorted by values of scores but still I can't print it on the web view</p>
  
  <pre><code>firebase.initializeApp(config);
  database = firebase.database();
  var ref = database.ref('scores');
  console.log(ref);
  ref.on('value', gotData, errData);
  
  function gotData(data) {
      var scorelistings = document.querySelectorAll('.scorelisting');
  
      for (var i = 0; i &lt; scorelistings.length; i++){
          scorelistings[i].remove();
      }
  
      var scores = data.val();
      var keys = Object.keys(scores);
      var olList = document.getElementById('list');
  
      for (var i = 0; i &lt; keys.length; i++) {
          var k = keys[i];
          var initials = scores[k].initials;
          var score = scores[k].score;
  
          var li = document.createElement('li');
          li.classList.add('scorelisting');
  
  
          $(olList).append(li);
          var scoreArr = $('ol').find('li');
          var count = $("ol").find("li").length;
  
          li.innerText = initials + ": " + score;
       }
  }
  
  function errData(err) {
      console.log('error');
  }
  
  function submitScore(e) {
      var data = {
          initials: nickname.value,
          score: score
      }
      e.preventDefault();
      // console.log(data);
      ref.push(data);
      scoreBoard.style.display = "none";
      highscoreBoard.style.display = "block";
  }
  </code></pre>