JSFiddle - React, Tailwind, and code Playground

by Michael Keller

JavaScript

var sets = [
{
    "uid": "a1",
    "quote": "Hey",
    "source": "NYT"},
{
    "uid": "a1",
    "quote": "Ho",
    "source": "FB"},
{
    "uid": "a2",
    "quote": "Hi",
    "source": "Reuters"
}];

var nested = {};

for (var set in sets) {
    if (sets.hasOwnProperty(set)) {
        var key = sets[set].uid;
        var entry = sets[set];
      
        // If this value is new, make it the key of a new array
        if (!nested[key]) {
            nested[key] = new Array;
        }

        // Get rid of the attribute that is the key
        //delete entry.uid

        // Create the nested object
        nested[key].push(entry)



    };
};

console.log('sets',sets);
console.log('nested', nested);