1
1

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.

Object.prototype.map()が欲しい!

Posted at

いきなり思いついたから書いた記事なんで、詳しい説明はありませんが。

Object.prototype.map=function(c){return Object.keys(this).map(k=>[k,c(this[k],k,this)]).reduce((a,e)=>(a[e[0]]=e[1],a),{})};

({
    foo: 1,
    bar: 2,
    baz: 4,
    qux: 6
}).map((item, key, object) => ++item);

/*\
|r| {
|e|     foo: 2,
|t|     bar: 3,
|u|     baz: 5,
|r|     qux: 7
|n| }
\*/

お役に立てれば幸いです。

1
1
3

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?