<!DOCTYPE html>
<html>
<body>
<h1>JavaScript 配列</h1>
<h2>sort()メソッド</h2>
<p>ボタンをクリックして、車のオブジェクトをタイプ別に並べ替えます。</p>
<button onclick="myFunction()">並び替える</button>
<p id="demo"></p>
<script>
const cars = [
{type:"Volvo", year:2016},
{type:"Saab", year:2001},
{type:"BMW", year:2010}
];
displayCars();
function myFunction() {
cars.sort(function(a, b){
let x = a.type.toLowerCase();
let y = b.type.toLowerCase();
if (x < y) {return -1;}
if (x > y) {return 1;}