Suraz Khanal Suraz Khanal - 1 year ago 82
AngularJS Question

How to group object value by key in angularjs

I have an object with this structure


Here I want to group each key with the similar value and put these to new object.
Just like

Answer Source

You could use an object and group by value.

var object = { aaas: "good", aasda: "ok", adasa: "good", ascas: "good", asdasd: "nw", asdasda: "nw", asdqw: "nw", assa: "ok", asscsa: "ok" },
    grouped = {};

Object.keys(object).forEach(function (k) {
    if (!grouped[object[k]]) {
        grouped[object[k]] = {};
    grouped[object[k]][k] = object[k];

.as-console-wrapper { max-height: 100% !important; top: 0; }

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download