HOME > > > >

sortedIndex

_.sortedIndex(array, value, [iteratee], [context])

array
array
value
mixed
[iteratee]
int
[context]
iteratee関数内のthis

第1引数の配列にvalueを挿入できるIndexを返す。 iteratee関数が提供されている場合は、渡した値も含めて、各値のソート順位の計算に使用されます。 反復対象は、ソートするプロパティの文字列名(たとえば、length)でも構いません。

サンプル

実行結果

実行 削除

Javascript

  1. const debug1 = new Debug('#code1-dump');
  2. $('span#code1-execute').on('click', (e) => {
  3.     const value = [10, 20, 30, 40, 50];
  4.     debug1.dump(_.sortedIndex(value, 35));
  5. });
  6.  
  7. $('span#code1-console-clear').on('click', (e) => {
  8.     debug1.clear();
  9. });

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>

サンプル

実行結果

実行 削除

Javascript

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

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>
参照サイト