Compare two values of a property of different json

2

I need to compare the value of a property from 2 different jsons to be able to show something on the screen. For example : 1st json:

{
registros: [
        {
            "paciente": 2,
            "problema": {
             "nota": "Mano derecha amputada. Antibioticos"
        },
{
            "paciente": 3,
            "problema": {
            "nota": "Ecografia de 6ta semana."
            }
        },
]}

2nd json:

{
pacientes: [
{
            "nroPaciente":  2,
            "nombre": "Anakin Skywalker",
            "edad": 50,
            "internado": true
        },
{
            "nroPaciente":  1,
            "nombre": "Emanuel Fernandez",
            "edad": 16,
            "internado": false
        }

]}

I need to compare the nroPaciente property with the other patient and if they are the same show the property note .  I just use javascript, I clarify that the jsons are obtained by a fetch and I'm showing other properties with a for, etc. Thanks:)

    
asked by lucas 11.09.2018 в 03:28
source

1 answer

0
var registros= {
registros: [
    {
        "paciente": 2,
        "problema": {
         "nota": "Mano derecha amputada. Antibioticos"
    }
 },
{
    "paciente": 3,
        "problema": {
        "nota": "Ecografia de 6ta semana."
        }
    },
]};
var pacientes= {
pacientes: [
{
        "nroPaciente":  2,
        "nombre": "Anakin Skywalker",
        "edad": 50,
        "internado": true
    },
{
        "nroPaciente":  1,
        "nombre": "Emanuel Fernandez",
        "edad": 16,
        "internado": false
    }

]};

function get_nota( pacienteid){
   let filtered=   registros.registros.filter(elemento=>elemento.paciente==pacienteid);
  return filtered[0];
}
//Recorrer pacientes, acceder a la propiedad pacientes que contiene
//la lista de los mismos
pacientes.pacientes.forEach( function(elemento){
    let pacienteCod= elemento.nroPaciente;
    console.log( get_nota( pacienteCod));

} 
);

By the way, you missed a key to close the first patient record

    
answered by 11.09.2018 / 04:46
source