JS
arr.push(element1[, ...[, elementN]]) arr.pop()
JS
var coffee = ['americano', 'latte', 'cappuccino', 'mocha']; var popped = coffeMenu.pop(); console.log(coffeMenu); // ['americano', 'latte', 'cappuccino'] console.log(popped); // 'mocha' var snack = ['scone', 'cookie']; Array.prototype.push.apply(coffee, snack); console.log(coffee); // ['americano', 'latte', 'cappuccino', 'scone', 'cookie']
JS
arr.unshift([...elementN]) arr.shift()
JS
const array1 = [1, 2, 3]; console.log(array1.unshift(4, 5)); // expected output: 5 console.log(array1); // expected output: Array [4, 5, 1, 2, 3] const array1 = [1, 2, 3]; const firstElement = array1.shift(); console.log(array1); // expected output: Array [2, 3] console.log(firstElement); // expected output: 1
JS
array.concat([value1[, value2[, ...[, valueN]]]])
JS
const alpha = ['a', 'b', 'c']; const numeric = [1, 2, 3]; alpha.concat(numeric); // 결과: ['a', 'b', 'c', 1, 2, 3] const num1 = [1, 2, 3]; const num2 = [4, 5, 6]; const num3 = [7, 8, 9]; num1.concat(num2, num3); // 결과: [1, 2, 3, 4, 5, 6, 7, 8, 9] const alpha = ['a', 'b', 'c']; alpha.concat(1, [2, 3]); // 결과: ['a', 'b', 'c', 1, 2, 3]