Object.extend = function (destination, source) {
/// <summary>
/// 扩展对象方法
/// </summary>
for (var property in source) {
destination[property] = source[property];
}
return destination;
}Object.extend(Array.prototype, {
each: function (iterator) {
/// <summary>
/// 遍历数组执行方法
/// </summary>
for (var i = 0, length = this.length; i < length; i++)
iterator(this[i]);
},
clear: function () {
/// <summary>
/// 清空数组
/// </summary>
this.length = 0;
return this;
},
indexOf: function (object) {
/// <summary>
/// 获取某项在数组中的位置
/// </summary>
for (var i = 0, length = this.length; i < length; i++)
if (this[i] == object) return i;
return -1;
},
remove: function (dx) {
/// <summary>
/// 移除指定索引出的对象
/// </summary>
if (isNaN(dx) || dx < 0 || dx > this.length) { return false; }
for (var i = 0, n = 0; i < this.length; i++) {
if (this[i] != this[dx]) {
this[n++] = this[i]
}
}
this.length -= 1
},
insertAt: function(index,obj){
/// <summary>
/// 在index处插入元素
/// </summary>
this.splice(index,0,obj);
},
removeAt: function(index){
/// <summary>
/// 移除index处元素
/// </summary>
this.splice(index,1);
}
})js Array扩展方法
原创
©著作权归作者所有:来自51CTO博客作者草宝虫啊的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Array数组常用方法——js/javascript
Array 对象用于在单个的变量中存储多个值,有很多方法,刻意很难记住,不记还总是忘,上笔记! 笔记代码:var arr = [1,2,3];v...
js javascript 数据结构 堆排序 gridview -
免费文字转语音,工具小巧无广告
后面带ZH标识的语音就可以了,语言资源很丰富。
#语音识别 #人工智能 #数据库 #服务器 #运维

















