Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

オブジェクトの分割代入について

const user = {
    id: 42,
    is_verified: true
};

const {id, is_verified} = user;

console.log(id); // 42
console.log(is_verified); // true

オブジェクトの分割代入が分からなくてmdnを見ていたんですが、

const {id, is_verified} = user;

これって意味あるんですか?
なにをやっているのかわからないです。

0 likes

1Answer

const id = user.id
const is_verified = user.is_verified

と同じことをしてます。
意味ないけど、書き方の例なので。

> const data = { a:1, b:2, c:3, d:4 }
undefined
> const {a, c} = data
undefined
> a
1
> c
3
0Like

Comments

  1. 詳しくありがとうございました。

Your answer might help someone💌