Javascript Array toDictionary(keySelector, valueSelector)

Description

Javascript Array toDictionary(keySelector, valueSelector)


Array.prototype.toDictionary = function (keySelector, valueSelector) {
 var o = {};/*from w  w w  .  jav  a  2 s  . c  o m*/
 var l = this.length;
 while (l-- > 0) {
  var key = keySelector(this[l]);
  if (key == null || key == "") continue;
  o[key] = valueSelector(this[l]);
 }
 return o;
};



PreviousNext

Related