当前位置:网站首页>Fast classification of array.group() in ES6
Fast classification of array.group() in ES6
2022-07-28 13:16:00 【Pig Xiaoyong】
List of articles
ES6 Medium Array.group() Quickly sort and combine arrays
1. Need to rely on babel, Install... In the project first
npm i core-js
2. introduce
import 'core-js/actual/array/group
3. Application scenarios
I have an array , According to some information in the array , Grouping .
example :
There is a set of customer information , Now it will be grouped according to provinces .
4. application
One line of code to solve
const orderList = [{
nickName: 'steven',
productName: ' watermelon ',
price: 29,
province: 'henan',
},{
nickName: ' The other person's ',
productName: ' Arbutus ',
price: 22,
province: 'shanxi',
},{
nickName: ' Fan battery ',
productName: ' Apple ',
price: 19,
province: 'dongbei',
},{
nickName: ' survey v',
productName: ' Peach ',
price: 88,
province: 'shanxi',
},{
nickName: '2 Number ',
productName: ' Peach ',
price: 88,
province: 'shanxi',
}]
const group=orderList.group(({
province})=>province)
console.log(group)

5. Implementation when not in use
const provinceObj = {
}
for (let index = 0; index < orderList.length; index++) {
const element = orderList[index]; // This data of the cycle object
const provinceKey = element.province // The province field in this data
// Determine whether the attribute exists in the empty object , Yes key Values exist push
if (provinceObj[provinceKey]) {
provinceObj[provinceKey].push(element)
} else {
// key Create a new one if the value does not exist key and value
provinceObj[provinceKey] = [element] //[element] Put this data into the array
}
}
console.log(provinceObj)
The results are the same 
边栏推荐
- Jetpack 全家桶之 LiveData 使用及源码篇
- 2020-12-27
- 【嵌入式C基础】第2篇:进制转换与BCD编码
- CTO of youhaoda, MVP of Huawei cloud, and Zhang Shanyou: build cloud native applications based on kubernetes and dapr
- [July 5 event preview] Flink Summit
- The difference between sessionstorage, localstorage and cookies
- 管理区解耦架构见过吗?能帮客户搞定大难题的
- Sub thread update UI full solution
- How to design a second kill system?
- SQL most commonly used basic operation syntax
猜你喜欢

Pointnet++ Chinese Translation

Installation and reinstallation of win11 system graphic version tutorial

UV germicidal lamp chip dlt8p65sa Jericho

Code layered management of interface testing based on RF framework
![[Bi design teaching] STM32 and FreeRTOS realize low power consumption](/img/2b/3af85135e08599aaa425698c0e83aa.png)
[Bi design teaching] STM32 and FreeRTOS realize low power consumption

LeetCode每日一题(2196. Create Binary Tree From Descriptions)
![[basic teaching of Bi design] detailed explanation of OLED screen use - single chip microcomputer Internet of things](/img/76/820d4e357206f936b33da92a5e2b5b.png)
[basic teaching of Bi design] detailed explanation of OLED screen use - single chip microcomputer Internet of things

How to design a second kill system?

Scala transformation, filtering, grouping, sorting

Risk analysis of option trading
随机推荐
How can non-standard automation equipment enterprises do well in product quality management with the help of ERP system?
《TiDB 6.x in Action》发布,凝聚社区集体智慧的 6.x 实践汇总!
SQL most commonly used basic operation syntax
[matlab]: FFT related problems
面试必问,敲重点!讲一下 Android Application 启动流程及其源码?
Machine learning practice - integrated learning-23
03 pyechars rectangular coordinate system chart (example code + effect drawing)
How to improve deep learning performance?
Qt 信号和槽机制( 详解 )
Use and source code of livedata in jetpack family bucket
Dimming and color matching cool light touch chip-dlt8ma12ts-jericho
Shenwenbo, researcher of the Hundred Talents Program of Zhejiang University: kernel security in the container scenario
Change the document type in endnode and import it in word
[FPGA]: MATLAB generates COE files
Brother bird talks about cloud native security best practices
Stepless dimming colorful RGB mirror light touch chip-dlt8s12a-jericho
【嵌入式C基础】第9篇:C语言指针的基本用法
[pictures and texts] detailed tutorial of one click reinstallation of win11 system
Rust 从入门到精通01-简介
Machine learning practice - logistic regression-19