LoginSignup
0
0

【JavaScript】camelCaseをsnake_caseに変換する方法

Posted at

以下のライブラリをインストールします。

$ yarn add decamelize-keys

以下のように使用します。

import decamelizeKeys from 'decamelize-keys';

// オブジェクトを変換
decamelizeKeys({fooBar: true});
//=> {foo_bar: true}

// オブジェクトの配列を変換
decamelizeKeys([{fooBar: true}, {barFoo: false}]);
//=> [{foo_bar: true}, {bar_foo: false}]

// separatorを変更する
decamelizeKeys({fooBar: true});
//=> {foo_bar: true}

decamelizeKeys({fooBar: true}, {separator: '-'});
//=> {'foo-bar': true}
0
0
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
0