let array=[{"typeName":"普工","amount":239},{"typeName":"焊工","amount":34},{"typeName":"技术员","amount":12},{"typeName":"测量员","amount":9},{"typeName":"其他人员","amount":9},{"typeName":"钢筋工","amount":8},{"typeName":"木工","amount":7},{"typeName":"技术负责人","amount":7},{"typeName":"电工","amount":5},{"typeName":"班组长","amount":5},{"typeName":"挖掘机司机","amount":5},{"typeName":"监理员","amount":4},{"typeName":"项目副经理","amount":4},{"typeName":"施工员","amount":3},{"typeName":"安全员","amount":3},{"typeName":"综合办职员","amount":3},{"typeName":"材料员","amount":3},{"typeName":"机械操作工","amount":3},{"typeName":"项目经理","amount":3},{"typeName":"总监代表","amount":2},{"typeName":"经营部部长","amount":2},{"typeName":"副总工","amount":2},{"typeName":"装载机机司机","amount":2},{"typeName":"土建监理工程师","amount":2},{"typeName":"旋挖钻机司机","amount":2},{"typeName":"工程部部长","amount":2},{"typeName":"施工队长","amount":2},{"typeName":"安全总监","amount":2},{"typeName":"电焊工","amount":2},{"typeName":"质量总监","amount":1},{"typeName":"吊车司机","amount":1},{"typeName":"机管员","amount":1},{"typeName":"土方司机","amount":1},{"typeName":"内业员","amount":1},{"typeName":"财务总监","amount":1},{"typeName":"安全监理工程师","amount":1},{"typeName":"试验员","amount":1},{"typeName":"质检员","amount":1},{"typeName":"统计员","amount":1},{"typeName":"试验室主任","amount":1},{"typeName":"合约监理","amount":1},{"typeName":"物设部部长","amount":1},{"typeName":"安环部副部长","amount":1},{"typeName":"经理助理","amount":1},{"typeName":"技术主管","amount":1},{"typeName":"资料员","amount":1},{"typeName":"总监理工程师","amount":1},{"typeName":"安环部长","amount":1},{"typeName":"人资专员","amount":1},{"typeName":"杂工","amount":74},{"typeName":"焊工(电焊工)","amount":16},{"typeName":"挖掘铲运和桩工机械司机","amount":12},{"typeName":"分包单位/其它分包管理人员","amount":9},{"typeName":"钢筋工","amount":9},{"typeName":"项目部/施工员","amount":8},{"typeName":"项目部/其它人员","amount":8},{"typeName":"电工","amount":6},{"typeName":"","amount":6},{"typeName":"项目部/测量员","amount":3},{"typeName":"桩机操作工","amount":3},{"typeName":"项目部/实验工程师","amount":3},{"typeName":"分包单位/工长","amount":3},{"typeName":"项目部/安全员","amount":2},{"typeName":"项目部/工长","amount":2},{"typeName":"项目部/预算员","amount":2},{"typeName":"安全员","amount":2},{"typeName":"分包单位/技术负责人","amount":2},{"typeName":"项目部/技术负责人","amount":2},{"typeName":"项目部/设备员","amount":2},{"typeName":"项目部/材料员","amount":1},{"typeName":"项目部/劳务管理员","amount":1},{"typeName":"项目部/质检员","amount":1},{"typeName":"木工","amount":1},{"typeName":"项目部/安全总监","amount":1},{"typeName":"项目部/造价工程师","amount":1},{"typeName":"项目部/项目总工","amount":1},{"typeName":"项目部/项目副经理","amount":1},{"typeName":"监理单位/总监代表","amount":1},{"typeName":"监理单位/土建监理工程师","amount":1},{"typeName":"项目部/资料员","amount":1},{"typeName":"项目部/项目经理","amount":1},{"typeName":"采购员","amount":1},{"typeName":"起重机司机(塔吊/升降机/物料)","amount":1},{"typeName":"施工员","amount":1},{"typeName":"监理单位/监理员","amount":1},{"typeName":"土石方挖掘机司机","amount":1},{"typeName":"起重工(安装起重工)","amount":1},{"typeName":"项目部/生产副经理","amount":1},{"typeName":"混凝土工","amount":1},{"typeName":"资料员","amount":1},{"typeName":"总包单位(专业承包单位)/安全负责人","amount":1},{"typeName":"杂工","amount":94},{"typeName":"","amount":85},{"typeName":"打桩工","amount":23},{"typeName":"桩机操作工","amount":11},{"typeName":"钢筋工","amount":10},{"typeName":"起重工(安装起重工)","amount":9},{"typeName":"焊工(电焊工)","amount":8},{"typeName":"项目部/设备员","amount":7},{"typeName":"电工","amount":6},{"typeName":"土石方挖掘机司机","amount":6},{"typeName":"项目部/施工员","amount":6},{"typeName":"项目部/其他项目管理人员","amount":5},{"typeName":"分包单位/工长","amount":5},{"typeName":"监理单位/监理员","amount":5},{"typeName":"混凝土工","amount":4},{"typeName":"起重信号工(起重信号司索工)","amount":4},{"typeName":"挖掘铲运和桩工机械司机","amount":3},{"typeName":"项目部/安全员","amount":3},{"typeName":"项目部/实验工程师","amount":2},{"typeName":"分包单位/项目经理","amount":2},{"typeName":"项目部/劳务管理员","amount":2},{"typeName":"项目部/项目副经理","amount":2},{"typeName":"资料员","amount":2},{"typeName":"监理单位/总监代表","amount":2},{"typeName":"项目部/技术负责人","amount":2},{"typeName":"其他","amount":2},{"typeName":"铲运机司机","amount":1},{"typeName":"项目部/仓库管理","amount":1},{"typeName":"分包单位/安全负责人","amount":1},{"typeName":"项目部/材料员","amount":1},{"typeName":"项目部/质检员","amount":1},{"typeName":"保安","amount":1},{"typeName":"总包单位(专业承包单位)/安全员","amount":1},{"typeName":"项目部/其它人员","amount":1},{"typeName":"项目部/安全总监","amount":1},{"typeName":"建设单位/项目技术负责人","amount":1},{"typeName":"项目部/测量员","amount":1},{"typeName":"项目部/项目经理","amount":1},{"typeName":"综合管理部/行政员","amount":1},{"typeName":"推土机司机","amount":1},{"typeName":"项目部/预算员","amount":1},{"typeName":"仓管员","amount":1},{"typeName":"安全员","amount":1},{"typeName":"项目部/生产副经理","amount":1},{"typeName":"分包单位/技术负责人","amount":1}]
let result = {};
array.forEach(item => {
if (result[item.typeName]) {
result[item.typeName] += item.amount;
} else { result[item.typeName] = item.amount; }
}
)
let s = [];
for (let k in result) {
s.push({
typeName: k, amount: result[k]
})
}
console.log(s)
数组中 某个键相等,让他们的值相加形成新数组
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...