I can use spread operator when I use object.
We use same object-key sometimes.
This operator can reduce repeat.
For example, First, I made 'cookie' object.
const cookie = {
base: "cookie",
madeIn: "korea"
}
and second, I made another object.
const cookie = {
base: "cookie",
madeIn: "korea"
}
const chocochipCookie = {
base: "cookie",
madeIn: "korea",
topping: "chocochip"
}
You know.
Key 'base' and 'madeIn' are same.
We need simple code.
Spread operator can reduce this code.
const cookie = {
base: "cookie",
madeIn: "korea"
}
const chocochipCookie = {
...cookie,
topping: "chocochip"
}
const blueberryCookie = {
...cookie,
topping: "blueberry"
}
const strawberryCookie = {
...cookie,
topping: "strawberry"
}
console.log(cookie)
console.log(chocochipCookie)
console.log(blueberryCookie)
console.log(strawberryCookie)
Finally, I reduced this code.
I use the spread operator for repeated space.
I think this operator is really simple!
I just need 'period'.
My English skills and grammar are not good.
But I'm trying!
I want to improve my English skills.
So sometimes I will write in English .
Thank you for visiting.
I'm junior developer!
I'm learning! 😊
300x250
'LEARN > JAVASCRIPT' 카테고리의 다른 글
[JS] 자바스크립트로 비밀번호 암호화 하기 👉 SHA-256 (0) | 2023.06.29 |
---|---|
[JavaScript] Ajax (0) | 2023.06.15 |
[JavaScript] 챗봇 내 스크롤링 기능 on/off (0) | 2022.12.27 |
[자바스크립트] localstorage 로컬스트리지 쓰기 읽기 제거 (0) | 2022.12.05 |
[자바스크립트] JavaScript typeOf 타입 확인 (0) | 2022.11.15 |