1
2

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.

js 分割代入 {}

Last updated at Posted at 2019-03-02

勉強中です

疑問

const {trade} = require('cointrader')

はい、意味が分かりません


ググったワード
const {}

検索結果4番目
https://ushumpei.hatenablog.com/entry/2016/06/29/032906

複雑で理解できませんでした。が、
・分割代入である
・分割代入 - JavaScript | MDN<=このページをみればよい
ということがわかりました。


オブジェクトの分割代入という項目を発見
これこれ、こういうのが欲しいの

簡単な例

var o = {p: 42, q: true};
var {p, q} = o;
console.log(p); // 42
console.log(q); // true


---

完全に理解した。超簡単に書くと

```js
{a} = {a: "hoge"}

で、右辺にオブジェクト、左辺にオブジェクトのキーを書けば、値を取得できる。
ここで、objectってkeyとvalueのペアであっているのかという疑問が生じる。。。
私の頭は容量が少なすぎて、簡単な言葉で説明できないと記憶してくれません。てことで後で調べる。

ということで試しにオンラインエディタで実行

const {a} = {a: "hello"}
console.log(a);

---
hello

はい、OK
ここまで10分でできたOK、OK
てことで次はObjectについて。

1
2
10

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?