LoginSignup
0
1

More than 5 years have passed since last update.

【JavaScript 】配列要素の追加と削除

Posted at

配列要素の追加と削除

'use strict';

const arr = [1, 2, 3];
console.log(arr); // [1, 2, 3]

// 配列の先頭に追加
arr.unshift(0);
console.log(arr); // [0, 1, 2, 3]

// 配列の先頭を削除
console.log(arr.shift()); // 0
console.log(arr); // [1, 2, 3]

// 配列の末尾に追加
arr.push(4);
console.log(arr); // [1, 2, 3, 4]

// 配列の末尾を削除
console.log(arr.pop()); // 4
console.log(arr); // [1, 2, 3]

※Google Chrome で確認
※ES8

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1