[Javascript] 배열 합치는 방법 5가지(concat, spread, push, Array.from, reduce)
1. concat() 메서드 const arr1 = [1, 2, 3]; const arr2 = [4, 5, 6]; const combined = arr1.concat(arr2); console.log(combined); // [1, 2, 3, 4, 5, 6] 2. Spread 연산자 const arr1 = [1, 2, 3]; const arr2 = [4, 5, 6]; const combined = [...arr1, ...arr2]; console.log(combined); // [1, 2, 3, 4, 5, 6] 3. push() 메서드 const arr1 = [1, 2, 3]; const arr2 = [4, 5, 6]; for (let i = 0; i < arr2.length; i++) { arr1.pu..
2023. 7. 17.