[Solved] Group JavaScript Array Items on their Value [closed]


You should iterate the initial array and create new objects keyed off the prNumber. Here’s how to do it using reduce (assuming you’ve assigned the array to a variable named orig):

var result = orig.reduce(function(prev, curr, index, arr) {
    var num = curr["prNumber"];
    if (!prev[num]) {
        prev[num] = [];
    }
    prev[num].push(curr["text"]);
    return prev;
}, {});

You can easily convert this into the example structure outlined in your question.

0

solved Group JavaScript Array Items on their Value [closed]