Skip to content

Instantly share code, notes, and snippets.

@akm
Created March 25, 2016 02:29
Show Gist options
  • Save akm/8576edae2517aa8437e7 to your computer and use it in GitHub Desktop.
Save akm/8576edae2517aa8437e7 to your computer and use it in GitHub Desktop.
環境変数など任意のオブジェクトをキーでソートしたオブジェクトを取得する ref: http://qiita.com/akm/items/1278af3873aa589da154
var obj = { ... }
Object.keys(obj).sort().reduce(function(d, k){ d[k] = obj[k]; return d;}, {})
$ node
> var obj = process.env
undefined
> Object.keys(obj).sort().reduce(function(d, k){ d[k] = obj[k]; return d;}, {})
{ DISABLE_SPRING: '1',
EDITOR: '/usr/bin/emacs',
LANG: 'ja_JP.UTF-8',
...
TMPDIR: '/var/folders/70/5yxt0jys7ss_m71y5pz_l_qc0000gn/T/' }
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment