查看“︁JavaScript/array”︁的源代码
来自康健生活
←
JavaScript/array
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 引言 == === 特点 === * 相同的数据类型 * 连续的线性内存 == 遍历 == === 判断 === <syntaxhighlight lang="javascript"> if (!this.length || this.length == 0) return this;</syntaxhighlight> == 示例 == === 去重 === <syntaxhighlight lang="javascript"> Array.prototype.uniq = function () { if (!this.length || this.length == 0) return this; var res = [], key, hasNaN = false, temp = {}; for (var i = 0 ; i < this.length; i++) { if (typeof this[i] === 'object') { res.push(this[i]); } else if (this[i] != this[i]) { // 如果当前遍历元素是NaN if (!hasNaN) { res.push(this[i]); hasNaN = true; } } else { key = typeof(this[i]) + this[i]; if (!temp[key]) { res.push(this[i]); temp[key] = true; } } } return res; }</syntaxhighlight> <syntaxhighlight lang="javascript"> Array.prototype.uniq = function () { var res = []; var flag = true; this.forEach(function(x) { if (res.indexOf(x) == -1) { if (x != x) { if (flag) { res.push(x); flag = false; } } else { res.push(x); } } }) return res; }</syntaxhighlight>
此页面嵌入的页面:
模板:Consoleout
(
查看源代码
)
模板:Double-columns
(
查看源代码
)
模板:Double-columns/style.css
(
查看源代码
)
模板:Unknown
(
查看源代码
)
返回
JavaScript/array
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。