1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

スプレッド演算子をオブジェクトに使用する

Posted at

Reactを学習していて、子コンポーネントにpropsを渡す際に{...todo}という表記があったので疑問になって調べた。

オブジェクトに使う場合

配列のみで使用できると思っていたスプレッド演算子だが、オブジェクトの中身を展開するためにも使用できることを知った。
以下の出力結果はどちらも同様。

const hoge = {a: 1, b: 2}
console.log(hoge)
// > Object { a: 1, b: 2 }
console.log({...hoge})
// > Object { a: 1, b: 2 }

ECMAScript 2018(ES9)からの新機能とのこと。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?