JSFiddle - React, Tailwind, and code Playground
HTML
<a href="group1/A"></a>
<a href="group1/B"></a>
<a href="group1/C"></a>
<a href="group2/C"></a>
<a href="group2/D"></a>
<a href="group2/E"></a>
<a href="group3/F"></a>
<a href="group3/G"></a>
<a href="group3/H"></a>
JavaScript
var subjects = {};
$('a').each(function(index) {
var prefix = $(this).attr("href").replace(/([^\/]*)\/.*/, "$1");
var name = $(this).attr("href").replace(/[^\/]*\/(.*)/, "$1");
if (!(prefix in subjects)) {
subjects[prefix] = new Array();
}
subjects[prefix].push(name);
});
console.log(subjects);