Created
February 1, 2022 10:36
-
-
Save mystikraz/1f62437a5264fc9858319cf7277bfa71 to your computer and use it in GitHub Desktop.
group by in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //arranging groupBy deviceId and Qty | |
| var result = []; | |
| cartItems.reduce(function (res, value) { | |
| if (!res[value.deviceId]) { | |
| res[value.deviceId] = { deviceId: value.deviceId, qty: 0 }; | |
| result.push(res[value.deviceId]) | |
| } | |
| res[value.deviceId].qty += value.qty; | |
| return res; | |
| }, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment