Nodejs Array Object Key asObject(labels)

Here you can find the source of asObject(labels)

Method Source Code

Array.prototype.asObject = function(labels) {
   var result = {};
   var _ctx = this;
   /*from  w w  w  . ja v a2s.c  om*/
   labels.each(function(label, idx) {
      if (label != null)
         result[label] = _ctx[idx];
   })
      
   return result;
}

Related

  1. 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;
        });
    };
    
  2. 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;
    
  3. options(textKey, valueKey)
    Array.prototype.options = function(textKey, valueKey) {
      var options = [];
      options = this.map(function(item) {
         return { text: item[textKey], value: item[valueKey] }
      });
      return options;
    
  4. 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;
    };
    
  5. arrToObj()
    Array.prototype.arrToObj = function(){
      var obj = {};
      for (var i = 0; i < this.length; i++) {
        obj[i] = this[i]
      return obj;
    
  6. 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;
    
  7. fromObject(obj)
    Array.prototype.fromObject = function (obj) {
        var ar = [];
        for(item in obj){
            ar.push(obj[item]);
        return ar;
    };
    
  8. getAllObjectsBy(field, withValue)
    Array.prototype.getAllObjectsBy = function(field, withValue)
      var results = [];
      for (var i = 0; i < this.length; i++) {
        if(this[i][field] == withValue)
          results.push(this[i]);
      return (results.length>0) ? results : null;
    
  9. replace(oldObj, newObj)
    Array.prototype.replace = function(oldObj, newObj){
       var indexOfOldItem = this.indexOf(oldObj)
       if(indexOfOldItem==-1){
          throw new Error("oldObj not in list")
       this[indexOfOldItem] = newObj
       return oldObj
    };
    Array.prototype._checkIndexInRange = function(index){
    ...