const fruits = ["apple", "orange", "banana"];
console.log(fruits.length); // 3

const emptyArr = [];
console.log(emptyArr.length); // 0
const greeting = "ようこそ。お会いできて嬉しいです!";
console.log(greeting.length); // 18

const emptyStr = "";
console.log(emptyStr.length); // 0
function myFunction(a, b, c) {
  console.log(arguments.length);
}

myFunction(); // 0
myFunction(1); // 1
myFunction(1, 2); // 2
myFunction(1, 2, 3); // 3
const elements = document.querySelectorAll("p");
console.log(elements.length); // 要素の個数
let str = "Hello, World!";
console.log(str.length); // 13

// length プロパティを変更しようと試みる
str.length = 5;

console.log(str.length); // 依然として 13
console.log(str);        // "Hello, World!" そのまま維持される
let arr = ["Apple", "Banana", "Orange", "Grape"];
console.log(arr.length); // 4

// 1. lengthを現在より小さく変更 (配列の短縮)
arr.length = 2; 
console.log(arr.length); // 2
console.log(arr);        // ["Apple", "Banana"] -> 残りの要素は永久に削除される

// 2. lengthを現在より大きく変更 (配列の拡張)
arr.length = 5;
console.log(arr.length); // 5
console.log(arr);        // ["Apple", "Banana", empty × 3] -> 空きスロット(hole)ができる

// 3. 再び元のデータに復元しようとしても、削除されたデータは戻らない
console.log(arr[2]);     // undefined