We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents c6d5349 + 99cbfeb commit 6d20dcbCopy full SHA for 6d20dcb
index.js
@@ -497,6 +497,21 @@ function for_in_range(num, callback) {
497
}
498
499
500
+/**
501
+ * Group by key in array of object
502
+ *
503
+ * @param array arr
504
+ * @param string key
505
+ * @returns object
506
+ */
507
+function group_by(arr, key) {
508
+ is_array(arr)
509
+ return arr.reduce(function (rv, x) {
510
+ (rv[x[key]] = rv[x[key]] || []).push(x);
511
+ return rv;
512
+ }, {});
513
+}
514
+
515
export {
516
is_array,
517
is_num_array,
@@ -525,4 +540,5 @@ export {
525
540
find_key_and_update,
526
541
find_and_update,
527
542
for_in_range,
543
+ group_by,
528
544
};
0 commit comments