회사에 들어오고 나서 코드를 파악하는데 some, includes, find 등등 생소했던 배열 method들이 있었다. 물론 map, filter, reduce와 같은 것들을 알고 활용할줄 안다면 이해하는데 어렵지 않겠지만 알고 있다면 정말 유용할것 같고 아직도 공부할게 산더미구나 라고 생각했었다.! 그래서 이참에 모르는 method들을 정리해서 기록해보기로 함 ㅋㅋ!
const array1 = [5, 12, 8, 130, 44];
let index = 2;
console.log(`Using an index of ${index} the item returned is ${array1.at(index)}`);
// Expected output: "Using an index of 2 the item returned is 8"
index = -2;
console.log(`Using an index of ${index} item returned is ${array1.at(index)}`);
// Expected output: "Using an index of -2 item returned is 130"
arr.copyWithin(target[, start[, end]])
onst array1 = ['a', 'b', 'c', 'd', 'e'];
// Copy to index 0 the element at index 3
console.log(array1.copyWithin(0, 3, 4));
// Expected output: Array ["d", "b", "c", "d", "e"]
// Copy to index 1 all elements from index 3 to the end
console.log(array1.copyWithin(1, 3));
// Expected output: Array ["d", "d", "e", "d", "e"]
코드로 보는게 젤 이해가 빠르다.
const array1 = [
[0, 1],
[2, 3],
[4, 5],
];
const result = array1.reduceRight((accumulator, currentValue) => accumulator.concat(currentValue));
console.log(result);
// Expected output: Array [4, 5, 2, 3, 0, 1]