javascript – How to group an array of objects by key


What is the most efficient way to groupby objects in an array?

var allGlobalRoles = ();

                Enumerable.From(BASF.HRAutomation.HiringApproval.objJobCatalogs)
                    .Where(function (thisObj) { return thisObj.JobFamily == $("#selectJobFamily").val() && thisObj.Role == valueSelected })
                    .GroupBy('$.GlobalJob', null, function (key, g) {
                        g.ForEach(function (item) {
                            allGlobalRoles.push(item);
                        });
                    })
                    .ToArray();

result: enter image description here

i want to display the dropdown the without duplicate values.