| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
                            Tags
                            
                        
                          
                          - 조건부스타일
- es6
- vite
- useQueryClient
- 리액트
- 문제해결
- QueryClient
- createPortal
- transition
- CustomHook
- Carousel
- tailwindCSS
- debouncing
- 서초구보건소 #무료CPR교육
- ?? #null병합연산자
- 부모요소의 패딩 무시
- 이즐 #ezl #욕나오는 #교통카드
- parent padding
- 부모패딩
- 화살표2개
- twoarrow
- react
- ignore padding
- accordian
- 함수형프로그래밍
- 제어컴포넌트
- DOM
- BlockFormattingContext
- alias설정
- BFC
                            Archives
                            
                        
                          
                          - Today
- Total
프론트엔드 첫걸음
Strange behavior of an array filled by Array.prototype.fill() 본문
Strange behavior of an array filled by Array.prototype.fill()
I face something I don't understand with an array. Indeed, I created an array I have filled with empty subArrays to obtain a 2D Matrix. But when I manipulate the array it doesn't behave as I expect...
stackoverflow.com
fill이라는걸 알게됐는데, fill은 primitive 타입에만 써야함.
fill([]) 해버리면 동일한 배열 참조하게해버림
var arr = new Array(5).fill([])
//arr[0] = arr[1] = arr[2] = arr[3] = arr[4] = [];
arr[2].push("third rank item");
console.log(arr);
//[ [ 'third rank item' ],
//  [ 'third rank item' ],
//  [ 'third rank item' ],
//  [ 'third rank item' ],
//  [ 'third rank item' ] ]이렇게 된다는 말임
'로그 > 문제상황' 카테고리의 다른 글
| 400 에러 발생 문제 해결 (1) | 2023.12.18 | 
|---|---|
| 전역으로 설치된 eslint 없애기 (0) | 2023.03.11 | 
| FirebaseError: Firebase: Error (auth/operation-not-allowed). (0) | 2022.10.20 | 
| [의문점미해결] inline EventListener에 event넘겨주기 (0) | 2022.08.14 | 
| 티스토리 Odyssey 스킨에 수정, 삭제 버튼 넣기 (0) | 2022.07.22 | 
 
           
                  