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

Object.entries() は「オブジェクトを for 文で回せる形にする」

0
Posted at

▼ 元のオブジェクト(fields)

const fields = {
  title: "案件名",
  overview: "案件概要",
  duration_month: "期間(月)",
  status: "ステータス",
};

これをそのまま map() で回すことはできません。

だから次のように配列へ変換します:

▼ Object.entries(fields)

[
  ["title", "案件名"],
  ["overview", "案件概要"],
  ["duration_month", "期間(月)"],
  ["status", "ステータス"]
]

このコードは…

const fieldEntries = Object.entries(fields);

fields の中身を「[キー, ラベル]」の配列に変換している

そして、これを map で回すことで、

fieldEntries.map(([key, label]) => {
    ...
})

のように key と label の両方を1行ずつ取り出せる!

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