源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

本地对象Array的原型扩展实现代码

  • 时间:2022-07-01 06:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:本地对象Array的原型扩展实现代码
[u]复制代码[/u] 代码如下:
Array.prototype.del=function(){ var b={},c,i=0,l=this.length,j; for(;i<l;i++){ c=this.shift(); c in b ? b[c]++ : b[c]=0; } for(j in b){ if(b[j]>0)this.push(+j||j); } return this; } var a=[1,2,2,3,3,3,'a','b','b']; alert(a.del());
果果的去重方法
[u]复制代码[/u] 代码如下:
Array.prototype.del=function(){ return (function (i, n, j, u, o){ for (; i < j; i++) { o = this[i]; o in u ? 0 : (u[this[n++] = o] = 1) } this.length = n; return this }).call(this, 0, 0, this.length, {}) } var a=[1,2,2,3,3,3,'a','b','b']; alert(a.del())
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部