HOME > > > >

object

_.object(list, [values])

list
array
[values]
array

配列をオブジェクトに変換します。 [key、value]ペアの単一リスト、またはキーのリストと値のリストのどちらかを渡します。重複キーが存在する場合は、最後の値が優先されます。

_.object(list)

[ [key, value], [key, value],... ]として渡す

サンプル

実行結果

実行 削除

Javascript

  1. const debug1 = new Debug('#code1-dump');
  2. $('span#code1-execute').on('click', (e) => {
  3.     const arg = [
  4.         [1996, '赤・緑・青'],
  5.         [1998, 'ピカチュウ'],
  6.         [1999, '金・銀'],
  7.         [2000, 'クリスタルバージョン'],
  8.         [2002, 'ルビー・サファイア'],
  9.         [2004, 'ファイアレッド・リーフグリーン/エメラルド'],
  10.         [2006, 'ダイヤモンド・パール'],
  11.         [2008, 'プラチナ'],
  12.         [2009, 'ハートゴールド・ソウルシルバー'],
  13.         [2010, 'ブラック・ホワイト'],
  14.         [2012, 'ブラック2・ホワイト2'],
  15.         [2013, 'X・Y'],
  16.         [2014, 'オメガルビー・アルファサファイア'],
  17.         [2016, 'サン・ムーン'],
  18.         [2017, 'ウルトラサン・ウルトラムーン'],
  19.         [2018, 'Let\'s Go! ピカチュウ・Let\'s Go! イーブイ'],
  20.     ];
  21.     const value = _.object(arg);
  22.     debug1.dump(value);
  23. });
  24.  
  25. $('span#code1-console-clear').on('click', (e) => {
  26.     debug1.clear();
  27. });

HTML

  1. <span class="cq-btn m-success" id="code1-execute">実行</span>
  2. <span class="cq-btn m-danger" id="code1-console-clear">削除</span>
  3. <div id="code1-dump"></div>

_.object(list, [values])

[key, key, key,..], [value, value, value,..] を渡す

サンプル

実行結果

実行 削除

Javascript

  1. const debug2 = new Debug('#code2-dump');
  2. $('span#code2-execute').on('click', (e) => {
  3.     const list = [
  4.         1996,
  5.         1998,
  6.         1999,
  7.         2000,
  8.         2002,
  9.         2004,
  10.         2006,
  11.         2008,
  12.         2009,
  13.         2010,
  14.         2012,
  15.         2013,
  16.         2014,
  17.         2016,
  18.         2017,
  19.         2018,
  20.     ];
  21.  
  22.     const value = [
  23.         '赤・緑・青',
  24.         'ピカチュウ',
  25.         '金・銀',
  26.         'クリスタルバージョン',
  27.         'ルビー・サファイア',
  28.         'ファイアレッド・リーフグリーン/エメラルド',
  29.         'ダイヤモンド・パール',
  30.         'プラチナ',
  31.         'ハートゴールド・ソウルシルバー',
  32.         'ブラック・ホワイト',
  33.         'ブラック2・ホワイト2',
  34.         'X・Y',
  35.         'オメガルビー・アルファサファイア',
  36.         'サン・ムーン',
  37.         'ウルトラサン・ウルトラムーン',
  38.         'Let\'s Go! ピカチュウ・Let\'s Go! イーブイ',
  39.     ];
  40.  
  41.     const obj = _.object(list, value);
  42.     debug2.dump(obj);
  43. });
  44.  
  45. $('span#code2-console-clear').on('click', (e) => {
  46.     debug2.clear();
  47. });

HTML

  1. <span class="cq-btn m-success" id="code2-execute">実行</span>
  2. <span class="cq-btn m-danger" id="code2-console-clear">削除</span>
  3. <div id="code2-dump"></div>
参照サイト