{...} ๐ŸŒฑspread Operator?

์œคยท2022๋…„ 10์›” 7์ผ
0

JavaScript

๋ชฉ๋ก ๋ณด๊ธฐ
5/11

์Šคํ”„๋ ˆ๋“œ ์—ฐ์‚ฐ์ž?๐ŸŒฑ

Spread ๋ผ๋Š” ๋‹จ์–ด์˜ ์˜๋ฏธ๋Š” ํŽผ์น˜๋‹ค, ํผ๋œจ๋ฆฌ๋‹ค ์ด๋‹ค.
์ด ๋ฌธ๋ฒ•์„ ์ด์šฉํ•˜๋ฉด, ๊ฐ์ฒด ํ˜น์€ ๋ฐฐ์—ด์„ ํŽผ์น  ์ˆ˜ ์žˆ๋‹ค. (๊ฐ์ฒด๋‚˜ ๋ฐฐ์—ด์„ ํ†ต์ฑ„๋กœ ๋Œ๊ณ ์™€์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅ!)
๊ธฐ์กด์˜ ๊ฒƒ์€ ๊ฑด๋“ค์ด์ง€ ์•Š๊ณ  ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

์˜ˆ>
  
// Spread ์‚ฌ์šฉ ์˜ˆ) ๊ฐ์ฒด์˜ ๊ฒฝ์šฐ
const a = {
  one: 'ํ•˜๋‚˜',
  two: '๋‘˜',
}
const b = {
  ...a,
  three: '์…‹'
}
console.log(b); // { one:'ํ•˜๋‚˜', two:'๋‘˜', three:'์…‹' }

// Spread ์‚ฌ์šฉ ์˜ˆ) ๋ฐฐ์—ด์˜ ๊ฒฝ์šฐ
const a = [1, 2, 3]
const b = [...a, 999, ...a]
console.log(b); // [1, 2, 3, 999, 1, 2, 3]

์ฐธ๊ณ 
https://learnjs.vlpt.us/useful/07-spread-and-rest.html

profile
ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž ์ž…๋‹ˆ๋‹ค.

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