반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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
Archives
Today
Total
관리 메뉴

taenyLog

[JavaScript] SPREAD (1) 배열 펼치기 본문

Web

[JavaScript] SPREAD (1) 배열 펼치기

taenyLog 2023. 9. 26. 09:51
반응형

spread : 전개구문

 

배열과 같이 반복 가능한 객체를 전개 구문을 사용해서 확장한다.

함수로 호출할 경우엔 0개 이상의 인수로 배열 리터럴에서는 요소로 확장할 수 있다.

객체 리터럴의 경우 객체 표현식은 0개 이상 키-값 쌍으로 확장할 수 있다.

 

The spread (...) syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected. In an object literal, the spread syntax enumerates the properties of an object and adds the key-value pairs to the object being created.

 

 

Spread 펼치다 .. 

const nums = [1 ,2, 3, 4, 22 2, 111, 523, 52352]

Math.max(nums) //NaN

Math.max(...nums) //52352

Math.max(nums)는 숫자가 아니라고 나온다. 숫자 전체의 배열이 들어가기 때문에

따라서 spread ... 를 써주면 배열이 펼쳐져서 숫자가 각각 들어간다.

 

숫자가 아닌 문자열도 가능하다. 문자열이 문자 하나하나로 분리됨

반응형