Nodejs Array Object Key options(textKey, valueKey)

Here you can find the source of options(textKey, valueKey)

Method Source Code

// Transform the underlying array to dynamic options.
Array.prototype.options = function(textKey, valueKey) {
  var options = [];
  options = this.map(function(item) {
     return { text: item[textKey], value: item[valueKey] }
  });/*from   w w w .  j a  va  2s. c o  m*/
  return options;
}

Related

  1. hasKey()
    Array.prototype.hasKey = function(){ 
      for(i in this){ 
        if(i === arguments[0]) 
          return true; 
      }; 
      return false; 
    };
    
  2. hasMultipleByKey(key)
    Array.prototype.hasMultipleByKey = function(key) {
        var foundOnce = false;
        var i = this.length - 1;
        while (i >= 0) {
            if (this[i].getKey() === key) {
                if (foundOnce)
                    return true;
                else
                    foundOnce = true;
    ...
    
  3. keys()
    Array.prototype.keys = function keys () {
      return new ArrayIterator(this, 'key');
    };
    
  4. notIn( key, array )
    Array.prototype.notIn = function( key, array )
        return this.filter( function(element)
            var flag = true;
            for(var i = 0; i < array.length; i++)
                if( element[key] == array[i][key]) flag = false;
            return flag;
        });
    };
    
  5. objectIndex(key,value)
    Array.prototype.objectIndex = function(key,value) {
      for(var i = 0, len = this.length; i < len; i++) {
          if (this[i][key] === value) return i;
      return -1;
    
  6. updateObject(id, key, value_key, value)
    Array.prototype.updateObject = function (id, key, value_key, value) {
      for (var i = 0; i < this.length; i++) {
        if (this[i][key] == value) {
          return this[i][value_key] = value;
    };
    
  7. arrToObj()
    Array.prototype.arrToObj = function(){
      var obj = {};
      for (var i = 0; i < this.length; i++) {
        obj[i] = this[i]
      return obj;
    
  8. asObject(labels)
    Array.prototype.asObject = function(labels) {
      var result = {};
      var _ctx = this;
      labels.each(function(label, idx) {
        if (label != null)
          result[label] = _ctx[idx];
      })
      return result;
    
  9. destroy(obj)
    Array.prototype.destroy = function(obj){
      var destroyed = null;
      for(var i = 0; i < this.length; i++){
        while(this[i] === obj){
          destroyed = this.splice(i, 1)[0];
      return destroyed;