惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
V
V2EX
B
Blog
腾讯CDC
D
DataBreaches.Net
H
Hackread – Cybersecurity News, Data Breaches, AI and More
月光博客
月光博客
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
云风的 BLOG
云风的 BLOG
Latest news
Latest news
L
LINUX DO - 最新话题
C
Check Point Blog
Attack and Defense Labs
Attack and Defense Labs
H
Hacker News: Front Page
Forbes - Security
Forbes - Security
H
Help Net Security
S
Securelist
D
Docker
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Last Watchdog
The Last Watchdog
N
News and Events Feed by Topic
G
Google Developers Blog
AI
AI
I
Intezer
L
LangChain Blog
NISL@THU
NISL@THU
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
T
Tenable Blog
Jina AI
Jina AI
I
InfoQ
C
Cybersecurity and Infrastructure Security Agency CISA
Cisco Talos Blog
Cisco Talos Blog
C
CERT Recently Published Vulnerability Notes
GbyAI
GbyAI
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
O
OpenAI News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Know Your Adversary
Know Your Adversary
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog

博客园 - 匆匆

Grunt常见问题 一个小型的类库 JavaScript 设计模式 HTML5常见问题 改版提示,新手指南 前端开发规范文档 常用正则表达式 JavaScript String 对象扩展方法 JavaScript String 对象常用方法 JavaScript Array 对象常用方法 JavaScript 常见基础问题二 JavaScript 常见基础问题一 JavaScript与网页性能 跨浏览器的本地存储解决方案 页面中添加事件、阻止事件传播、事件删除 常用CSS书写技巧 Gridview用法大总结(牛年珍藏版) 总结一些常用功能源码 JS类库
JavaScript Array 对象扩展方法
匆匆 · 2012-07-02 · via 博客园 - 匆匆
/** 删除数组中指定索引的数据 **/
Array.prototype.deleteAt = function (index) {
    if (index < 0) {
        return this;
    }
    return this.slice(0, index).concat(this.slice(index + 1, this.length));
}
/** 数组洗牌 **/
Array.prototype.random = function () {
    var tempArr = [], me = this, t;
    while (me.length > 0) {
        t = Math.floor(Math.random() * me.length);
        tempArr[tempArr.length] = me[t];
        me = me.deleteAt(t);
    }
    return tempArr;
}
Array.prototype.orderRandom = function () {
    return this.sort(function () {
        return Math.random() > 0.5 ? "-1" : "1";
    });
}
/** 数字数组排序 **/
Array.prototype.sortNum = function (i) {
    if (!i) {
        i = 0;
    }
    if (i == 1) {
        return this.sort(function (a, b) {
            return b - a;
        });
    }
    return this.sort(function (a, b) {
        return a - b;
    });
}
/** 获取数字数组中的最大项 **/
Array.prototype.getMax = function () {
    return this.sortNum(1)[0];
}
/** 获取数字数组中的最小项 **/
Array.prototype.getMin = function () {
    return this.sortNum(0)[0];
}
/** 数组第一次出现指定元素的位置 **/
Array.prototype.indexOf = function (o) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == o) {
            return i;
        }
    }
    return -1;
}
/** 去除数组中的重复项 **/
Array.prototype.arrUnique = function () {
    var reset = [], done = {};
    for (var i = 0; i < this.length; i++) {
        var temp = this[i];
        if (!done[temp]) {
            done[temp] = true;
            reset.push(temp);
        }
    }
    return reset;
}