Nodejs Array Value unset(value,isIndex)

Here you can find the source of unset(value,isIndex)

Method Source Code


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Array.prototype.unset = function(value,isIndex) {

   var isIndex = isIndex || 0;
   //from  w w  w .ja  va 2 s. co  m
   if (value == undefined) {
      
      this.length = 0;
      
      return this;
   }
   
   for (var i = 0, j = 0, l = this.length; i < l; ++i) {
   
      if (!isIndex) {
         
         if (this[i] != value) { 
         
            this[j++] = this[i];
         }
      
      } else {
         
         if (i != value) {
            
            this[j++] = this[i];
         }
      }
   }
   
   this.length = j;
   
   return this;
};

Related

  1. superJoin(value)
    isNullOrEmpty=function(obj) {
        if (obj == undefined || obj == null || obj == "") {
            return true;
        else {
            return false;
    Array.prototype.superJoin=function(value){
    ...
    
  2. toggleValue(value)
    Array.prototype.toggleValue = function (value) {
        var index = this.indexOf(value);
        if (index === -1) {
            this.push(value);
        else {
            this.splice(index, 1);
    };
    ...
    
  3. trim(value)
    Array.prototype.trim = function (value) {
      var array = this.slice(0); 
      while (array.length > 0 && array[0] === value) {
        array.shift();
      while (array.length > 0 && array[array.length - 1] === value) {
        array.pop();
      return array;
    ...
    
  4. tw_indexOf(val)
    Array.prototype.tw_indexOf = function(val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        return -1;
    };
    Array.prototype.tw_remove = function(val) {
        var index = this.indexOf(val);
        if (index > -1) {
    ...
    
  5. unset(value)
    Array.prototype.unset = function (value) {
        if (this.indexOf(value) !== -1) { 
            this.splice(this.indexOf(value), 1);
    };
    
  6. unset(value,isIndex)
    Array.prototype.unset = function(value,isIndex) {
      var isIndex = isIndex || 0;
      if (value == undefined) {
        this.length = 0;
        return this;
      for (var i = 0, j = 0, l = this.length; i < l; ++i) {
        if (!isIndex) {
          if (this[i] != value) { 
    ...
    
  7. valueIndexOf(val)
    Array.prototype.valueIndexOf = function(val) {
      for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
      return -1;
    };
    
  8. valuesAt(indices)
    Array.prototype.valuesAt = function(indices) {
      var ary = this;
      return indices.map(function(idx) { return ary[idx] });
    };
    
  9. asArray(val)
    Array.asArray = function(val){
        if(Array.isArray(val)){
            return val;
        } else {
            return [val];