配列要素追加と削除 unshift push shift pop

const arr = ["one", "two"];
console.log(arr.unshift("zero"));  // 3
console.log(arr);  // ["zero", "one", "two"]
console.log(arr.push("three"));  // 4
console.log(arr);  // ["zero", "one", "two", "three"]
console.log(arr.shift());  // zero
console.log(arr);  // ["one", "two", "three"]
console.log(arr.pop());  // three
console.log(arr);  // ["one", "two"]

先頭に追加 unshift  戻り値:追加後の個数
末尾に追加 push     戻り値:追加後の個数
先頭を削除 shift    戻り値:削除した要素
末尾を削除 pop      戻り値:削除した要素

shift, pop は要素を一つずつしか削除できないので、()に何かを書く必要はない。

unshift, push は複数の追加要素を記述できる  arr.push(“four”,”five”,”six”)