Nodejs Array Delete by Value delRepeat()

Here you can find the source of delRepeat()

Method Source Code

Array.prototype.delRepeat = function () {// extend the 'Array'
        var temp = {}, len = this.length;
        for (var i = 0; i < len; i++) {
            var tmp = this[i];
            if (!temp.hasOwnProperty(tmp)) {// hasOwnProperty can check dictonary have that key
                temp[this[i]] = "yes";
            }//www . jav a  2s .co  m
        }
        var y = 0,result = [];
        for (var te in temp) {
            result[y++] = te;
        }
        return result;
}
   
function delRepeatExample () {
        var arr = [];
        for (var i = 0; i < 10000; i++) {
            var t = parseInt(Math.random() * 10);
            arr[i] = (t.toString());
        }
        var s = new Date();// start time
        var a=arr.delRepeat();
        var dd = new Date() - s;//end time=(current time)-(start time)
      console.log(dd);
}

function transferImgUrl(imgurl){
   var lasti=imgurl.lastIndexOf(".");
   var length=imgurl.length;
   return imgurl.substring(0, lasti-2)+imgurl.substring(lasti, length);
}

Related

  1. del(val)
    Array.prototype.del = function(val){
        var index = this.indexOf(val);
        if(index > -1)
            this.splice(index, 1);
    
  2. delete(element)
    Array.prototype.delete = function(element)
         for (i=0;i<this.length;i++)
             if(this[i]==element)
                 this.splice(i,1);
    
  3. delete(item)
    Array.prototype.delete = function(item) {
      var index = -1;
      for (var i = 0; i < this.length; i++) {
        if (item === this[i]) {
          index = i;
          break;
      if (index != -1) {
    ...
    
  4. delete(value)
    Array.prototype.delete = function(value){
      return(this.filter(function(n){ return n != value; }));
    };
    
  5. deleteByValue(val)
    Array.prototype.deleteByValue=function(val){
        for (var i in this){
            if(this[i]===val){
                this.splice(i,1)
                break