Sublime Text
<!DOCTYPE html> <html> <body> <script> var student = [ {name:"Chung", age:17}, {name:"Anh", age:18}, {name:"Bao", age:15} ]; document.write("<hr>MẢNG BAN ĐẦU<hr>"); document.write("<p>" + student[0].name + " - " + student[0].age + "</p>"); document.write("<p>" + student[1].name + " - " + student[1].age + "</p>"); document.write("<p>" + student[2].name + " - " + student[2].age + "</p>"); student.sort(function(a, b){ if (a.name.toLowerCase() < b.name.toLowerCase()) {return -1;} if (a.name.toLowerCase() > b.name.toLowerCase()) {return 1;} return 0; }); document.write("<hr>MẢNG SAU KHI SẮP XẾP<hr>"); document.write("<p>" + student[0].name + " - " + student[0].age + "</p>"); document.write("<p>" + student[1].name + " - " + student[1].age + "</p>"); document.write("<p>" + student[2].name + " - " + student[2].age + "</p>"); </script> </body> </html>
<!DOCTYPE html> <html> <body> <script> var student = [ {name:"Chung", age:17}, {name:"Anh", age:18}, {name:"Bao", age:15} ]; document.write("<hr>MẢNG BAN ĐẦU<hr>"); document.write("<p>" + student[0].name + " - " + student[0].age + "</p>"); document.write("<p>" + student[1].name + " - " + student[1].age + "</p>"); document.write("<p>" + student[2].name + " - " + student[2].age + "</p>"); student.sort(function(a, b){ if (a.name.toLowerCase() < b.name.toLowerCase()) {return -1;} if (a.name.toLowerCase() > b.name.toLowerCase()) {return 1;} return 0; }); document.write("<hr>MẢNG SAU KHI SẮP XẾP<hr>"); document.write("<p>" + student[0].name + " - " + student[0].age + "</p>"); document.write("<p>" + student[1].name + " - " + student[1].age + "</p>"); document.write("<p>" + student[2].name + " - " + student[2].age + "</p>"); </script> </body> </html>