HOME > > > >

pluck

_.pluck(list, propertyName)

listに含まれるオブジェクトのpropertyNameを配列として返す

list
array
propertyName
string

サンプル

実行結果

実行 削除

Javascript

  1. var debug1 = new Debug('#code1-dump');
  2.  
  3.  
  4. $('#code1-execute').on('click', function(e){
  5.     var data = [
  6.         {name: '柳田 悠岐', team: 'ソフトバンク', ops: 1.168, nicename: 'ギータ'},
  7.         {name: '秋山 翔吾', team: '西武', ops: 1.005},
  8.         {name: '中村 奨吾', team: 'ロッテ', ops: 0.842},
  9.         {name: '森 友哉', team: '西武', ops: 0.851},
  10.         {name: '浅村 栄斗', team: '西武', ops: 0.925}
  11.     ];
  12.  
  13.     // name のリスト
  14.     debug1.dump(_.pluck(data, 'name'));
  15.  
  16.     // プロパティが存在しない場合は undefined
  17.     debug1.dump(_.pluck(data, 'nicename'));
  18. });
  19.  
  20. $('#code1-console-clear').on('click', function(e){
  21.     debug1.clear();
  22. });

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" class="result-window"></div>
参照サイト