JSFiddle - React, Tailwind, and code Playground

JavaScript

var data = [{
    'studyid': 'awesome',
    'templateid': ''
},
{
    'studyid': 'awesome',
    'templateid': 'custom awesome'
},
{
    'studyid': 'outstanding',
    'templateid': ''
}];

var templates = _.chain(data)
.groupBy(function (o){
    return o.templateId || o.studyId;
})
.value();

console.log(templates);