const array = [1, 2, 3, 4, 5]
const mapArray = array.map(item => item * 2)
console.log(mapArray)
// [2, 4, 6, 8, 10]
const array=[1, 2, 3, 4, 5]
const filterArray=array.filter(item => item % 2 === 0)
console.log(filterArray)
// [2, 4]
const array=[1, 2, 3, 4, 5]
const reduceArray=array.reduce((a, b) => a + b)
console.log(reduceArray)
// 15
배열의 일부분을 추출하는 함수
- 배열.splice(시작index, 끝index)
const array = [1, 2, 3, 4, 5]
const sliceArray = array.slice(2, 4)
console.log(array)
// [1, 2, 3, 4, 5]
console.log(sliceArray)
// [3, 4] 인덱스 2부터 인덱스 4 이전까지 추출하니까 3,4
배열의 일부 아이템을 삭제하고 추가할 수 있는 함수
- splice(시작index, 삭제 개수, 추가할 아이템)
- 추가할 아이템은 선택사항이다.
const array = [1, 2, 3, 4, 5]
const spliceArray = array.splice(1, 2, 7, 8)
console.log(array)
// [1, 7, 8, 4, 5]
console.log(spliceArray)
// [2, 3]