I need to have similar JSON structure:
{
"group1": ["A", "B", "C"],
"group2": ["C", "D", "E"],
"group3": ["F", "G", "H"]
}
and need to create it in cycle:
courses.each(function(index) {
name = $(this).attr("href").replace(/([^\/]*)\/.*/, "$1");
prefix = $(this).attr("href").replace(/[^\/]*\/(.*)/, "$1");
if (subjects.indexOf(prefix) == -1) {
subjects[prefix] = new Array();
}
subjects[prefix].push(name);
});
The courses variable is DOM object from sth like this:
<a href="group1/A">...
<a href="group1/B">...
<a href="group2/D">...
After the cycle execution, it contents sth like this:
[Array[0], "group1", "group2"]
not the structure mentioned above...
Why?