[Javascript] Spread Operator

Inah-_-ยท2021๋…„ 8์›” 6์ผ
0

Javascript

๋ชฉ๋ก ๋ณด๊ธฐ
4/5
post-thumbnail

{ ...} Spread Operator๋ž€? ๐Ÿ“Ÿ

ES6์—์„œ ์ถ”๊ฐ€๋œ ์ƒˆ๋กœ์šด ์—ฐ์‚ฐ์ž๋กœ, ์˜์–ด ๋œป ๊ทธ๋Œ€๋กœ spread ์ฆ‰, ํŽผ์น˜๋‹ค์˜ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ 
๊ฐ์ฒด๋‚˜ ๋ฐฐ์—ด์„ ํŽผ์ณ์„œ ๋‚˜์—ด ํ•  ๋•Œ์— ์‚ฌ์šฉํ•œ๋‹ค.

๋ฐฐ์—ด ๋ณ‘ํ•ฉ

// ๋ฐฐ์—ด ๋ณ‘ํ•ฉ
const arr = [1, 2, 3, 4, 5]

console.log([...arr, 6])
// Expected Output : [1, 2, 3, 4, 5]

๋ฐฐ์—ด ๋ณต์ œ

// ๋ฐฐ์—ด ๋ณ‘ํ•ฉ
const arr = [1, 2, 3, 4, 5]
const newArray = [...array];

console.log(newArray)
// Expected Output : [1, 2, 3, 4, 5]

ํŠน์ • ๊ฐ’ ๋ณ€๊ฒฝ

const objA = [a:1, b:2, c:3, d:4, e:5]
const objB = { ...objA, b:7};

console.log(objB)
// Expected Output : [a:1, b:7, c:3, d:4, e:5]
profile
Backend Developer

0๊ฐœ์˜ ๋Œ“๊ธ€