See the Pen Untitled by nilgi (@nilgi) on CodePen.
• 숫자 순서대로
displayCup();
cup.sort(function(a, b){return a.year - b.year});
displayCup();
function displayCup() {
document.getElementById("wcup").innerHTML =
cup[0].type + " " + cup[0].year + "<br>" +
.
.
. }
• 문자 순서대로
displayCup2();
function myFunction() {
cup2.sort(function(a, b){
let x = a.type.toLowerCase();
let y = b.type.toLowerCase();
if (x < y) {return -1;}
if (x > y) {return 1;}
return 0;
});
displayCup2();
}
function displayCup2() {
document.getElementById("wcup2").innerHTML =
cup2[0].type + " " + cup2[0].year + "<br>" +
.
.
. }