Nodejs Array Object Key singleRemove(objectToRemove)

Here you can find the source of singleRemove(objectToRemove)

Method Source Code

/**/*w  w  w . java 2 s .  c o m*/
The arguments global variable apparently slow considerably,
it should be used only when there's multiple things to delete
**/
Array.prototype.singleRemove = function(objectToRemove) {
    if ((index = this.indexOf(objectToRemove)) !== -1) {
        this.splice(index,1);
    }
    return this;
}

Related

  1. 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;
    
  2. fromObject(obj)
    Array.prototype.fromObject = function (obj) {
        var ar = [];
        for(item in obj){
            ar.push(obj[item]);
        return ar;
    };
    
  3. 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;
    
  4. 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){
    ...
    
  5. 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;