LoginSignup
0
1

More than 3 years have passed since last update.

[React.js] 配列・オブジェクトのループ表示

Last updated at Posted at 2020-07-17

配列ループ

const items = [1,2,3,4,5]
return (
  <div>
    <ul>
      {items.map((item) => (
        <li>{ item }</li>
      ))}
    </ul>
  </div>
);

オブジェクトループ

const items = {
  1: "ピカチュウ",
  2: "リザードン",
  3: "カイリュー",
  4, "ゲンガー",
  5: "カビゴン",
  6: "ギャラドス"
}
return (
  <div>
    <ul>
      {Object.keys(items).map(key => (
        <li key={key}>
          {items[key]}
        </li>
      ))}
    </ul>
  </div>
);
0
1
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
1