카테고리 없음

드림코딩 by 엘리. JavaScript 기초 강의(8) - 배열 제대로 알고 쓰자. 자바스크립트 배열 개념과 APIs 총 정리

i독 2021. 10. 7. 04:15

Array 기초 개념 생략

 

forEach > Callback 함수를 받아온다.

forEach(callbackfn: (valueTindexnumberarrayT[]) => voidthisArg?: any): void;

Calls a defined callback function on each element of an array, and returns an array that contains the results.

 

Callback 함수를 선언하여 각자 실행할 있다

example)

frutirs.forEach(funtion(fruit, index, array) { console.log(fruit, index, array) } //  보통은 Array 받아오진 않음으로 생략한다.

<- 이름이 없는 함수(anonymous function) Arrow function으로 사용 ->

frutirs.forEach((fruit, index) => console.log(fruit, index))

 

Array 추가 삭제 기초 생략

push / pop

unshift / shift - array control 특성상 애는 겁나 느림

 

splice(index, cnt) > index 부터 cnt까지 삭제