I have a JSON file which is structured as follows :
{"products":[
{ "tvs":[
{"samsung":[
{"leds":[
{
"product_id": "034567",
"product_name": "Samsung UA22F5100 22'' LED TV (Black)",
"model_no": "UA22F5100",
"brand": "Samsung",
"price": 399,
"screen_size": 22,
"screen_res": "1920 x 1080",
"usb": 1,
"hdmi": 1,
"screen_format": "LED",
"dimensions": "513.1 x 366.5 x 169.6",
"manuf_guarantee": "1 year"
},
{
"product_id": "012468",
"product_name": "Samsung 23F4003 23'' LED TV (Black)",
"model_no": "23F4003",
"brand": "Samsung",
"price": 459,
"screen_size": 23,
"screen_res": "1366 x 768 pixels",
"usb": 1,
"hdmi": 1,
"screen_format": "LED",
"dimensions": "551.9 x 368.4 x 123.4",
"manuf_guarantee": "1 year"
}
]},
{"plasma":[
{
"product_id": "043291",
"product_name": "Samsung 43F4100 43'' Plasma TV (Black)",
"model_no": "43F4100",
"brand": "Samsung",
"price": 399,
"screen_size": 43,
"screen_res": "852 x 480",
"usb": 2,
"hdmi": 2,
"screen_format": "Plasma",
"dimensions": "1007.4 x 670.5 x 261.9",
"manuf_guarantee": "1 year"
},
etc...
I need to iterate over this after I retrieve the results from an ajax request. I would need to filter data for example, get only leds' objects.
What is the best way to filter :
should I use jquery's .each(), or a for in loop ?
I am trying to iterate it using the .each() approach, but I am stuck on the part where I need to check if current object is 'leds' or 'plasma'.
On the other hand, if I use for (var x in obj), I get access to the name of the object through 'x' ..
So should I do it using for in loop? and how exactly would I do it?