I need to join two arrays, from the server I get the next json. an array that says "data" that has 2 objects and another that is called "Doc" which is made up of 4 objects.
I want to create a matrix that contains 8 elements equal to the following (I did it by hand):
[
{
"idlibrosiva": 1,
"iddoc": 1,
"false": 1
},{
"idlibrosiva": 1,
"iddoc": 2,
"false": 1
},{
"idlibrosiva": 1,
"iddoc": 3,
"false": 1
},{
"idlibrosiva": 1,
"iddoc": 4,
"false": 1
},{
"idlibrosiva": 2,
"iddoc": 1,
"false": 1
},{
"idlibrosiva": 2,
"iddoc": 2,
"false": 1
},{
"idlibrosiva": 2,
"iddoc": 3,
"false": 1
},{
"idlibrosiva": 1,
"iddoc": 4,
"false": 1
}]
This is what I get from the server in json
{
"status": "success",
"code": 200,
"data": [
{
"idlibrosiva": 1,
"nombre": "Compras",
"descripcion": "Art.-141 C.T.",
"estado": 1
},
{
"idlibrosiva": 2,
"nombre": "Contribuyentes",
"descripcion": "Artículo 141. C.T.- ",
"estado": 1
},
],
"Doc": [
{
"**iddoc**": 1,
"documento": "CREDITO FISCAL",
"descripcion": "ART. 107 C.C.",
"estado": 1
},
{
"iddoc": 2,
"documento": "NOTA DE CREDITO",
"descripcion": "ART. 110 C.C- ",
"estado": 1
},
{
"iddoc": 3,
"documento": "FACTURA",
"descripcion": "ART. 107 C.C.",
"estado": 1
},
{
"iddoc": 4,
"documento": "NOTA DE DEBITO",
"descripcion": "ART. 110 C.C.-",
"estado": 1
},
],
"mensaje": "Todo se ha cargado correctamente"}
I tried to do it like this:
this.Info = response.data;
this.liva = response.data.filter((item) => item.estado == 1);
this.docs = response.Doc.filter((item) => item.estado == 1);
this.DocYlib = this.liva.map((item)=>{
const DocumentoUtilizado = new ModeloDocUtilizadosIVA();
DocumentoUtilizado.Libro = item.idlibrosiva;
DocumentoUtilizado.estado = false;
DocumentoUtilizado.documento = this.docs.map((item) => item.iddoc);
return DocumentoUtilizado;
})
But the result has been: