I have two arrays of objects. One with a json variable and one with an information variable. The information variable is the one that should be equal to the json variable. This is because, information is data from the front and json is data from the database, so I must check that this information is totally the same. In this case the example that I put in all are the same. But it is just for example. So what should I do:
- Compare the information variable with the json variable.
- Start comparing data by data.
- If the data is the same a message 'Everything went well' and if not 'there is an error'
I was trying it like this so that it goes through all the data but it throws me certain errors, such as the same element going through me twice. I was reading that it can also be done with filter, I have seen a lot of documentation but I cannot implement it in my case. Below in the code I show with whom to compare
var json = [
{
Transacción: "999999",
Tarjeta: "0190",
Tipo: "Contr ctdo",
FechaDePago: "07/08/2022",
Ventas: "-5.000,00",
},
{
Transacción: "999997",
Tarjeta: "0194",
Tipo: "Contr ctdo",
FechaDePago: "06/08/2022",
Ventas: "4.000,00",
},
{
Transacción: "999998",
Tarjeta: "0195",
Tipo: "Contr ctdo",
"FechaDePago": "08/08/2022",
Ventas: "6.000,00",
},
];
var informacion = [
{
Trx: "Contr ctdo",
Fecha: "07/08/2022",
TermLoteCupon: "999999",
Tarj: "0190",
VentasconDto: "-5.000,00",
},
{
Trx: "Contr ctdo",
Fecha: "06/08/2022",
TermLoteCupon: "999997",
Tarj: "0194",
VentasconDto: "4.000,00",
},
{
Trx: "Contr ctdo",
Fecha: "08/08/2022",
TermLoteCupon: "999998",
Tarj: "0195",
VentasconDto: "6.000,00",
},
];
// The comparison should be that the data object array must be equal to the
array of json objects.
//The comparison is :
//Trx must be equal to Tipo
//Fecha must be equal to FechaDePago
//TermLoteCupon must be equal to Transacción
// Tarj must be equal to Tarjeta
//VentasconDto must be equal to Ventas
// What I did was the following:
for (let i = 0; i < informacion.length; i++) {
console.log('soy newarray', informacion[i]);
for(let j = 0; j < json.length; j++){
console.log('soy json parseado',json[j]);
if(json[j] == informacion[i]){
console.log('La informacion es compatible')
}else{
console.log('Hay error.')
}
}
}

The OP just ...
informacionarray has to match its counterpart item of different key-value pairs from the example'sjsonarray) ...informacionarray byArray.prototype.everywhile passing each currently processedinformacionitem together with itsjsoncounterpart-item where the latter is determined by the currentidx-value.As soon as the
everybased comparison process hits a mismatch, the iteration stops and returns the booleanfalsevalue whereas an uninterrupted full cycle means that all the requirements/conditions have been met, thuseveryreturning the booleantruevalue.