js笔记

作者: REIGE | 来源:发表于2017-09-19 23:21 被阅读0次

js数组 删除某个元素

Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};

Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

js数组是否含有某个元素

Array.prototype.contains = function ( needle ) {
  for (i in this) {
    if (this[i] == needle) return true;
  }
  return false;
}

判断value为undefined

if(typeof(value)=="undefined"){ 
alert("undefined"); 
} 

cookie操作

//清除所有cookie
function clearAllCookie() {
    var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
    if(keys) { 
        for(var i = keys.length; i--;)
            document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString();
    }
}

相关文章

网友评论

      本文标题:js笔记

      本文链接:https://www.haomeiwen.com/subject/dmxnsxtx.html