0
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 1 year has passed since last update.

jsでobject型である連想配列の中身を取り出す。

Posted at

結論

JavaScript
    formName (object) {
      return Object.keys(object).map((key) => {
        return { id: object[key].id, name: object[key].id + ' : ' + object[key].name }
      })
    }

解説

Object.keysを使用することにより配列のように扱えることとと
値を抽出する時は object[key].idのようにする。

mapのvalueを使い
map((key,value) => {
value.id
value.name
のようにしたくなるが、valueには配列の番号しかはいっていないため
目的の値を取り出すことはできない。

0
2
1

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
0
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?