6
6

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のhashをmapで処理する

6
Last updated at Posted at 2018-06-23

javascriptでのhashをmapで処理する

  • rubyでmapをよく使うのでjsでも使いたいな〜と思って調べた
  • hashでmapを使う
  • hashから配列にする
  • 多重配列バージョンは以前、「javascriptでmapを使う」に書いた

keyを取得


var test = {};
test['a'] = 1;
test['b'] = 2;
test['c'] = 3;

// keysで配列のkeyを取得
Object.keys(test)
=> ["a", "b", "c"]

こんな感じでmap使った

var test = {};
test['a'] = 1;
test['b'] = 2;
test['c'] = 3;

// keysで配列のkeyを取得してmap使う
Object.keys(test).map(function (key) {return test[key]})
=> [1, 2, 3]

 以上!!あざした!!

6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?