배열 합치기
![[JS] 다중 배열 하나의 배열로 묶기 (flat)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2Ft8X0M%2FbtrxY43XYxq%2FAAAAAAAAAAAAAAAAAAAAAPJ-GHAJxwmKKyeu8ojBspOxKLKTYmEFU6gWsr2i0Qkm%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DOx6SNXwaKcePJxu471zdXXaOMPw%253D)
[JS] 다중 배열 하나의 배열로 묶기 (flat)
flat 메서드 const newArr = arr.flat([depth]) flat 메서드는 모든 배열 요소를 지정한 깊이까지 이어 붙인 새로운 배열을 생성하는 메서드입니다. 빈 요소가 있으면 무시하며 depth에 따라 합치는 정도를 정할 수도 있습니다. (기본은 1입니다.) [1, 2, [3, 4]].flat(); // [1, 2, 3, 4] [1, 2, [3, 4, [5, 6]]].flat(); // [1, 2, 3, 4, [5, 6]] [1, 2, [3, 4, [5, 6]]].flat(2); // [1, 2, 3, 4, 5, 6] [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]].flat(Infinity); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 어디서 ..