JavaScrip笔记1
作者:互联网
定时执行
window.setInterval(function(){
alert("123")
}, 500);
数组去重
function removeDuplicatedItem(ar) {
var ret = [];
ar.forEach(function(e, i, ar) {
if (ar.indexOf(e) === i) {
ret.push(e);
}
});
return ret;
}
数组按值删除项
Array.prototype.deleteElementByValue = function(varElement)
{
var numDeleteIndex = -1;
for (var i=0; i<this.length; i++)
{
// 严格比较,即类型与数值必须同时相等。
if (this[i] === varElement)
{
this.splice(i, 1);
numDeleteIndex = i;
break;
}
}
return numDeleteIndex;
}
标签:function,笔记,numDeleteIndex,ar,JavaScrip,数组,var,ret 来源: https://blog.csdn.net/lftxd1/article/details/111690717