8
5

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 5 years have passed since last update.

Javascriptで連想配列の各要素への処理

Last updated at Posted at 2017-01-31

Reactにおいて、連想配列とObject.keys、mapを使って
プルダウンのオプションタグを生成する例。

サンプルコード

map.js
const data = {
	'book': '',
	'phone': '電話',
	'box': ''
}

const options = Object.keys(data).map((value, index) => {
	return(
		<option key={index} value={index}>{value}</option>
	);
});

解説

Object.keys

連想配列のキーを取り出してArrayで返却

Array.map

Arrayの要素とキーを順番に取り出して、コールバック関数を実行

8
5
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
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?