I have the following array of objects which I need to map the values of their properties to one that is appropriate for another system, for that, I generated a dictionary with each key-value.
Array example:
{
"data": [
{
"_id": 22,
"uuid": "xxxxxxxx",
"lugar_inscripcion": "mdhyh",
"nombre_apellido": "Juan Perez",
"tipo_up": "grupo_asociativo",
"nombre_up_emprend_negocio": "ConstruiMas",
"comienzo_activ_up": "2021-10-14"
},
{
"_id": 23,
"uuid": "xxxxxx",
"lugar_inscripcion": "domicilio_propio_o_up",
"nombre_apellido": "Juan Carlos",
"tipo_up": "emprendedor_individual",
"nombre_up_emprend_negocio": "Almacen La Ponderosa",
"comienzo_activ_up": "2022-03-23",
"calle_up": "Nazca"
}
]
}
How do I iterate over each of the objects and retrieve the value of each property to be able to do the .get method of the Map and change the value of the corresponding one?
An example of the map:
const mapLugar = new Map();
map.set('mdhyh', 'Ministerio');
map.set('grupo_asociativo', 'grupo_asoc');
map.set('emprendedor_individual', 'emp_ind');
The idea would be that after the iteration, the values change to the corresponding equivalent in the map.
{
"data": [
{
"_id": 22,
"uuid": "xxxxxxxx",
"lugar_inscripcion": "Ministerio",
"nombre_apellido": "Juan Perez",
"tipo_up": "grupo_asoc",
"nombre_up_emprend_negocio": "ConstruiMas",
"comienzo_activ_up": "2021-10-14"
},
{
"_id": 23,
"uuid": "xxxxxx",
"lugar_inscripcion": "domicilio_propio_o_up",
"nombre_apellido": "Juan Carlos",
"tipo_up": "emp_ind",
"nombre_up_emprend_negocio": "Almacen La Ponderosa",
"comienzo_activ_up": "2022-03-23",
"calle_up": "Nazca"
}
]
}
Thank you
If what you want to do is convert each element of an array into a
Map
and assign its properties, you can do it like this:Using
Object.entries
get the key->value pairs and pass them to theMap
The solution was as follows: