I was trying to follow this Getting JSON object values by name but I can't get it.
My data comes from this JSON: The green boxes show the values arrays and objets that I need to use.
http://fotos.subefotos.com/2a862e55595038ab73ab2f0805b83c15o.png
So I need to find the object inside the array "options" which has the id == 233 and then return it's "value", I'm trying to do it with this function:
function getReqVal(val) {
for (var item in datos_puros[0].campos[0].campos[0].options) {
if(item.id == val) {
return item.value;
}
}
}
I'm bringin the val like this:
getReqVal(datos_puros[0].campos[0].campos[0].value[0])
//console.log(datos_puros[0].campos[0].campos[0].value[0]) --> 233, it works
(datos_puros comes from an previous ajax call)
datos_puros = obj.estructura;
but I can't see where's my error. Please help
This is was I'm trying to do: https://jsfiddle.net/pmiranda/jrnfL9hp/1/