I am working with NodeJS by retrieving the information from the REST API, I need to parse it, I have the following Object and I need to remove it from the array
sensor_type
the entire object that does not have the name equal to the attrName.
{
"DatagreenhouseRecuperado":[
{
"_id":999,
"medidas":[
{
"_id":"5cccb38f796936d12ef7586d",
"marca":"Metos",
"modelo":"Estacion",
"fabricante":"Metos",
"id_station":[
999
],
"sensor_type":[
{
"name":44,
"type":"clima",
"place":"interior",
"img":"assets/img/hum.png",
"name_comun":"Temperatura",
"medida":"%",
"interfaz":""
},
{
"name":33,
"type":"clima",
"place":"interior",
"img":"assets/img/hum.png",
"name_comun":"Hum. Relativa",
"medida":"%",
"interfaz":""
}
],
"attrName":33,
"attrValue":8888,
"recvTimeTs":1588524826,
"recvTime":"2020-05-03T18:53:46"
}
],
"count":1
},
{
"_id":191,
"medidas":[
{
"_id":"5cc85899a0160f16c50f4199",
"marca":"Hortisis",
"modelo":"Estacion",
"fabricante":"Hortisis",
"id_station":[
191,
457
],
"sensor_type":[
{
"name":2,
"type":"clima",
"place":"interior",
"img":"assets/img/hum.png",
"name_comun":"Hum. Relativa",
"medida":"%",
"interfaz":""
},
{
"name":3,
"type":"clima",
"place":"interior",
"img":"assets/img/hum.png",
"name_comun":"Hum. Relativa",
"medida":"%",
"interfaz":""
}
],
"attrName":3,
"attrValue":2222,
"recvTimeTs":1554134499,
"recvTime":"2019-09-01T16:01:11.000Z"
}
],
"count":1
},
{
"_id":457,
"medidas":[
{
"_id":"5cc85899a0160f16c50f4199",
"marca":"Hortisis",
"modelo":"Estacion",
"fabricante":"Hortisis",
"id_station":[
191,
457
],
"sensor_type":[
{
"name":2,
"type":"clima",
"place":"interior",
"img":"assets/img/hum.png",
"name_comun":"Hum. Relativa",
"medida":"%",
"interfaz":""
},
{
"name":3,
"type":"clima",
"place":"interior",
"img":"assets/img/hum.png",
"name_comun":"Hum. Relativa",
"medida":"%",
"interfaz":""
}
],
"attrName":2,
"attrValue":555,
"recvTimeTs":1554134471,
"recvTime":"2019-04-01T16:01:11.000Z"
}
],
"count":1
}
]
}
For example, in the first case you would have to delete the object:
{
"name":44,
"type":"clima",
"place":"interior",
"img":"assets/img/hum.png",
"name_comun":"Temperatura",
"medida":"%",
"interfaz":""
}
since the attrName is 33.
I am not very sure how to do it, I have thought about going through the entire object and when it finds a name that is different from attrName, delete that object, but I don't know how to delete that object and not the name element.
Thanks greetings.
You can do it in the following way:
I hope this is what you need, regards!