
push()array.push(element1[, ...[, elementN]]);
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/push
pop()const lastElement = array.pop();
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/pop
shift()const firstElement = array.shift();
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
unshift()array.unshift(element1[, ...[, elementN]]);
unshift()를 이용하여 작업을 수행하고 배열명을 콘솔창에 입력해준다.unshift()를 이용하여 작업을 수행하면, 변경된 배열의 새로운 길이가 반환된다.var arr = [1, 2];
arr.unshift(0); // 3 (변경된 배열의 새로운 길이)
arr; // [0, 1, 2]
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
splice()array.splice(start[, deleteCount[, item1[, item2[, ...]]]]);
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
sort()array.sort([compareFunction]);
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
reverse()array.reverse();
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse
fill()array.fill(value[, start[, end]]);
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
map()const newArray = array.map(callback(currentValue[, index[, array]]) {
// return element for newArray, after executing something
});
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/map
filter()const newArray = array.filter(callback(element[, index[, array]]) {
// return true if the element passes the condition
});
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
slice()const newArray = array.slice(start[, end]);
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
concat()const newArray = array.concat(value1[, value2[, ...[, valueN]]]);
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
flatMap()map()과 유사하지만, callback에서 반환된 배열을 평평하게 평탄화한 후 하나의 배열로 반환한다.const newArray = array.flatMap(callback(currentValue[, index[, array]]) {
// return element or new array
});
💡 Reference : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap
// 1️⃣ 새로운 배열을 반환하는 메서드 (비변형 메서드)
const originalArray = [1, 2, 3, 4, 5];
const mappedArray = originalArray.map(item => item * 2);
// map(): [2, 4, 6, 8, 10]
// 각 요소를 두 배로 곱한 새로운 배열을 반환한다.
const filteredArray = originalArray.filter(item => item > 2);
// filter(): [3, 4, 5]
// 주어진 조건을 만족하는 요소만으로 이루어진 새로운 배열을 반환한다.
const slicedArray = originalArray.slice(1, 3);
// slice(): [2, 3]
// 인덱스 1부터 2까지의 요소로 이루어진 새로운 배열을 반환한다.
const concatenatedArray = originalArray.concat([6, 7, 8]);
// concat(): [1, 2, 3, 4, 5, 6, 7, 8]
// 주어진 배열이나 값들을 기존 배열에 추가한 새로운 배열을 반환한다.
const flatMappedArray = originalArray.flatMap(item => [item, item * 2]);
// flatMap(): [1, 2, 2, 4, 3, 6, 4, 8, 5, 10]
// 각 요소를 주어진 함수에 매핑한 후, 결과 배열을 평탄화하여 새로운 배열을 반환한다.
// 2️⃣ 기존의 배열을 수정하는 메서드 (변형 메서드)
let mutatingArray = [1, 2, 3, 4, 5];
mutatingArray.push(6);
// push(): 변형된 배열 -> [1, 2, 3, 4, 5, 6]
// 배열의 끝에 요소를 추가하고, 변경된 배열의 길이를 반환한다.
const poppedElement = mutatingArray.pop();
// pop(): 제거된 요소 -> 6, 변형된 배열 -> [1, 2, 3, 4, 5]
// 배열의 마지막 요소를 제거하고 반환한다.
const shiftedElement = mutatingArray.shift();
// shift(): 추가된 요소 -> 1, 변형된 배열 -> [2, 3, 4, 5]
// 배열의 첫 번째 요소를 제거하고 반환한다.
mutatingArray.unshift(0);
// unshift(): 변형된 배열 -> [0, 2, 3, 4, 5]
// 배열의 시작 부분에 요소를 추가하고, 변경된 배열의 새 길이를 반환한다.
mutatingArray.splice(2, 0, 2.5);
// splice(): 변형된 배열 -> [1, 2, 2.5, 3, 4, 5]
// 배열의 요소를 추가하거나 제거하여 배열을 수정한다.
mutatingArray.sort((a, b) => a - b);
// sort(): 변형된 배열 -> [1, 2, 2.5, 3, 4, 5]
// 배열을 제자리에서 정렬하고 반환한다.
mutatingArray.reverse();
// reverse(): 변형된 배열 -> [5, 4, 3, 2.5, 2, 1]
// 배열의 요소 순서를 반전시킨다.
const filledArray = new Array(5).fill(0);
// fill(): 변형된 배열 -> [0, 0, 0, 0, 0]
// 배열의 요소를 정적 값 하나로 채운다.