I have the following flat array
let data = [
["0000001", "SCHOLL", "S", "CEDULA", "NOESTUDIANTE", "GRADO"],
["0000002", "MOVIL", "S", "CELULAR", ""],
["0000003", "ECHALE", "S", "CONTRATO", "NOCLIENTE", ""],
];
And I have the following function, But this function returns me an array within another array of references, so I would like to be able to assign keys to the values that come flat, I have tried everything, but I don't know very well how to do it, if you could help me please and grateful for your comments
function infoTransform(values) {
return values.map((value) => {
let [service, name, ...references] = value;
service = parseInt([value[0]]);
references = references.filter((reference) => reference !== "");
references = references.splice(1);
let Myjson = JSON.stringify(references);
return {
service,
name,
Myjson,
};
});
}
console.log(infoTransform(data));
I wish it would return something like this to me
let data = [
{
id: 1,
name: "SCHOLL",
REF1: "CEDULA",
REF2: "NOESTUDIANTE",
REF3: "GRADO",
},
{ id: 2, name: "MOBILE", REF1: "CEDULA" },
{ id: 3, name: "EPALEE", REF1: "NOFOOD", REF2: "FOOBAR" },
];