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

推荐订阅源

P
Proofpoint News Feed
T
Tenable Blog
T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
C
CERT Recently Published Vulnerability Notes
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Vercel News
Vercel News
P
Palo Alto Networks Blog
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 最新话题
阮一峰的网络日志
阮一峰的网络日志
C
CXSECURITY Database RSS Feed - CXSecurity.com
Google DeepMind News
Google DeepMind News
Project Zero
Project Zero
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
The Last Watchdog
The Last Watchdog
博客园_首页
D
Docker
MyScale Blog
MyScale Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Hacker News
The Hacker News
云风的 BLOG
云风的 BLOG
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
The Blog of Author Tim Ferriss
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
S
Schneier on Security
C
Check Point Blog
I
Intezer
S
Securelist
雷峰网
雷峰网
小众软件
小众软件
C
Cyber Attacks, Cyber Crime and Cyber Security
PCI Perspectives
PCI Perspectives
S
Security @ Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
量子位
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
A
About on SuperTechFans
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
F
Fortinet All Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news

博客园 - 我就是那个王小明

git修改历史提交记录名字 gitbase配置两个git仓库源头地址 yarn dev 或者 npm run dev 或node -v 等报错:'node' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 htmlToPdf ES6 Generator使用 - 我就是那个王小明 - 博客园 前端开发快速定位bug的一些小技巧 基本css拼图形 forEach时候删除数组某一属性项,使用splice容易出现问题 对于vue的一些理解 配置vuex并使用 vue搭建开发环境 一些意想不到的小bug。 小程序开发中遇到的问题 rem原理 vue使用webpack压缩后体积过大要怎么优化 分别使用ES5和ES6进行数组去重以及注意事项 nodeJS理解 package.json和bower的参数解释 Angular.js基础
数组中的每一项按照某个属性分组 - 我就是那个王小明 - 博客园
我就是那个王小明 · 2018-12-25 · via 博客园 - 我就是那个王小明
var wang = [{g: 1, c:"aa"}, {g: 1, c: "bb"}, {g: 4, c: "cc"}, {g: 2, c: "dd"}, {g: 2, c:"ee"}, 
        {g: 2, c: "ff"}, {g: 3, c: "gg"}];

        var xxx = wang.map(function(item) {
            return item.g;
        });
        console.log("xxx: ",xxx);

        var yyy = [];
        xxx.forEach(function(item) {
            if (yyy.length > 0) {
                if (yyy.indexOf(item) > -1) {
                    return 
                } else {
                    yyy.push(item);
                }
            } else {
                yyy.push(item);
            }
        });
        console.log("yyy: ",yyy);

        var zzz = [];
        yyy.forEach(function(item) {
            zzz.push(wang.filter(function(apItem) {
                return apItem.g == item;
            }));
        })
        console.log("zzz: ",zzz);

简化附带说明版本:

 var wang = [{g: 1, c:"aa"}, {g: 1, c: "bb"}, {g: 4, c: "cc"}, {g: 2, c: "dd"}, {g: 2, c:"ee"}, 
        {g: 2, c: "ff"}, {g: 3, c: "gg"}];

        //提取所有g值得数组
        var xxx = wang.map(function(item) {
            return item.g;
        });
        console.log("xxx: ",xxx);

        //返回去重之后的数组。
        var yyy = [];
        xxx.forEach(function(item) {
            !(yyy.indexOf(item) > -1) && yyy.push(item)
        });
        console.log("yyy: ",yyy);

        var zzz = [];
        yyy.forEach(function(item) {
            //每次循环都会分组,分好的组分别push到zzz
            zzz.push(wang.filter(function(apItem) {
                return apItem.g == item;
            }));
        });

console.log("zzz: ",zzz);