I have a matrix with "seccion" keys and I want to join it by "seccion". Help me here I leave an example. I am already grateful for your support. Sorry for my English
At the beginning I have this then try to join them:
{0: {seccion: "0", stitulo: "titulo_test1"},
1: {seccion: "0", ssub: "sub_test1"},
2: {seccion: "1", stitulo: "titulo_test2"},
3: {seccion: "1", ssub: "sub_test2"}
}
What I do is go through all the objects with an assigned class, but the "i" counter overwrites them:
var secciones={};
$('#formSecciones').find('.secc').each(function(i,s) {
secciones[`$(s).closest('.dd-item').attr('data-id')] = {};
secciones[`$(s).closest('.dd-item').attr('data-id')][i] = {};
secciones[`$(s).closest('.dd-item').attr('data-id')][i][s.name] = s.value;
});
Result:
{0:{1:{ssub: "sub_test1"}},
1:{3:{ssub: "sub_test2"}}
}
This is what I want to get:
{0: {ssub: "sub_test1", stitulo: "titulo_test1"},
1: {stitulo: "titulo_test2", ssub: "sub_test2"}
}