title: How do I sort a two dimensional array in JavaScript?
body: <p>My sorting function at the end isn't working. I want to sort student grades in ascending order but I can't get it to print out. My sorting function goes through and manually compares however I can't get it to work. The problem may be that the student class is whats being used to add values to the array. </p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;script&gt;
      class Student {
          constructor(name,grade) {
              this.name = name;
              this.grade = grade;
          }
           detail() {
              document.writeln(this.name + " " + this.grade + "&lt;br/&gt;")
           }
      }
      var grade = [];
      var count = 0;
  
      function setStudent() {
          var name = prompt("Enter Name", "name");
          while(name != '???') {
                  var grades= parseInt(prompt("Enter Grade", "Grade"));
                  var student = new Student(name,grades);
                  grade.push(student);
                  name = prompt("Enter Name", "name");
                  count++
                  }
          }
  
      function showGrades() {
          for(i=0;i&lt;count;i++) {
              grade[i].detail();
          }
      }
      function maxGrade() {
          var mgrade = grade[0].grade;
          var names = "";
          for (i=0;i&lt;count;i++) {
              if(mgrade&lt;grade[i].grade) {
                  mgrade=grade[i].grade;
                  names = grade[i].name
              }
          }
          document.writeln("Max Grade: " + mgrade + " Name: " + names);
      }
  
      setStudent();
      showGrades();
      maxGrade(); 
      document.writeln("&lt;br/&gt; Assorted List (Ascending): &lt;br/&gt;"); 
  
      grade.sort(function(a,b) {
          return a[0] - b[0] || a[1] - b[1];
      });
      console.log(grade);
  
  
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>