Created
June 4, 2024 06:18
-
-
Save sukeharu/fd014aee1ba7aa8b91de56957595da9a to your computer and use it in GitHub Desktop.
スプレッド構文を使ってオブジェクトをコピー
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// スプレッド構文でオブジェクトをコピーする | |
const original = { | |
a: 1, | |
b: 2, | |
c: 3, | |
}; | |
const copied = {...original}; | |
console.log(copied); // {a: 1, b: 2, c: 3} | |
// スプレッド構文を使えばディープコピーができる | |
original.a = 10; // originalのプロパティ値を変更 | |
console.log(copied.a); // 1 | copiedプロパティの値は変わらない |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment