1.闭包

2.JS操作和获取cookie

//创建cookie
function setCookie(name, value, expires, path, domain, secure) {
var cookieText = encodeURIComponent(name) + '=' + encodeURIComponent(value);
if (expires instanceof Date) {
cookieText += '; expires=' + expires;
}
if (path) {
cookieText += '; expires=' + expires;
}
if (domain) {
cookieText += '; domain=' + domain;
}
if (secure) {
cookieText += '; secure';
}
document.cookie = cookieText;
} //获取cookie
function getCookie(name) {
var cookieName = encodeURIComponent(name) + '=';
var cookieStart = document.cookie.indexOf(cookieName);
var cookieValue = null;
if (cookieStart > -1) {
var cookieEnd = document.cookie.indexOf(';', cookieStart);
if (cookieEnd == -1) {
cookieEnd = document.cookie.length;
}

3.js数组去重

function arr1() {
var n = []; //一个新的临时数组
for (var i = 0; i < this.length; i++) //遍历当前数组
{
//如果当前数组的第i已经保存进了临时数组,那么跳过,
//否则把当前项push到临时数组里面
if (n.indexOf(this[i]) == -1) n.push(this[i]);
}
return n;
} function arr2(){
var n = {},r=[]; //n为hash表,r为临时数组
for(var i = 0; i < this.length; i++) //遍历当前数组
{
if (!n[this[i]]) //如果hash表中没有当前项
{
n[this[i]] = true; //存入hash表
r.push(this[i]); //把当前数组的当前项push到临时数组里面
}
}
return r;
} function arr3(){
var n = [this[0]]; //结果数组
for(var i = 1; i < this.length; i++) //从第二项开始遍历
{
//如果当前数组的第i项在当前数组中第一次出现的位置不是i,
//那么表示第i项是重复的,忽略掉。否则存入结果数组
if (this.indexOf(this[i]) == i) n.push(this[i]);
}
return n;
}

4.

 

最新文章

  1. SQL2005 表分区亲测
  2. Leetcode Candy
  3. CSS布局概述
  4. XGBoost参数
  5. 开源入侵检测系统OSSEC搭建之二:客户端安装
  6. asp.net Server.HtmlEncode和HtmlDecode
  7. 我的第一个QML Button的实现
  8. Java 面向对象(转)
  9. OC-Protocol实现业务代理
  10. Struts源码之OgnlValueStack
  11. charles模拟手机流量网速
  12. Python 爬虫 之 阅读呼叫转移(一)
  13. Python 隔离环境 virtualenv
  14. python3基础-set
  15. python作业高级FTP
  16. hdu 3015
  17. Pro * c Oracle 12c
  18. 【LeeCode88】Merge Sorted Array★
  19. C语言面试题5
  20. Delphi XE10.1 引用计数

热门文章

  1. nginx 重写
  2. thinkphp model
  3. hdu 6127 : Hard challenge (2017 多校第七场 1008)(计算几何)
  4. The list of list is modified unexpected, python
  5. 【Python】安装Python3,打印HelloWorld
  6. FastDFS整合nginx(三)
  7. 基于ELK Stack7.1.0构建多用户安全认证日志系统
  8. Android解析编译之后的所有文件(so,dex,xml,arsc)格式
  9. 【HDOJ6646】A + B = C(模拟)
  10. mac的jvm调优工具