Web

[JavaScript] SPREAD (2) 배열 복사

taenyLog 2023. 9. 26. 10:14
반응형

In Array Literals 

Create a new array using an existing array. Spreads the elements from one array into a new array.

 

반복 가능한 객체를 어떻게 펼치는가 ? 

 

배열을 복사해서 쓴다.

const fruits = ['apple', 'banana'];
const vegetables = ['cucumber','lettuce','cabbage'];

const allGroceries = [...fruits, ...vagetabkes]

allGroceries 호출시 'apple', 'banana' , 'cucumber','lettuce','cabbage' 가 호출된다.

배열 두개를 묶어서 새로운 배열을 만들었다.

 

 

반응형