Nodejs Array Object Key destroy(obj)

Here you can find the source of destroy(obj)

Method Source Code

Array.prototype.destroy = function(obj){
   // Return null if no objects were found and removed
   var destroyed = null;

   for(var i = 0; i < this.length; i++){
      // Use while-loop to find adjacent equal objects
      while(this[i] === obj){
         // Remove this[i] and store it within destroyed
         destroyed = this.splice(i, 1)[0];
      }/*from   w ww  . ja v  a2 s  . co  m*/
   }

   return destroyed;
}

Related

  1. 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;
    
  2. 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;
    
  3. 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;
    };
    
  4. arrToObj()
    Array.prototype.arrToObj = function(){
      var obj = {};
      for (var i = 0; i < this.length; i++) {
        obj[i] = this[i]
      return obj;
    
  5. 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;
    
  6. fromObject(obj)
    Array.prototype.fromObject = function (obj) {
        var ar = [];
        for(item in obj){
            ar.push(obj[item]);
        return ar;
    };
    
  7. 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;
    
  8. 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){
    ...
    
  9. seen(obj)
    Array.prototype.seen = function (obj) {
      if (obj.type == 'notification') {
        var i = 0;
        while (this[i].noticeId != obj.noticeId && i < this.length)
          i++;
        return (i < this.length && this[i].seqN < obj.seqN);
      return false;