Q:

Filtering required from object from array of objects

My Structure of data will be like below  
 var data = {"Questions" : [
                  {"QID":"Q1","S":"2"},
                  {"QID":"Q2","T":"12"},   
                  {"QID":"Q3","U":"22"}], // Also please suggest me to improve this to make parsing easier
             "Share" : "Yes"
            };
 for(var item in data.Questions)
 {
    if(this.QID == "Q2") // this.QID returns me undefined
    {
        // I want to retrieve the total object i.e
        // {"QID":"Q2","T":"12"} should be returned
    }
 }

Why does this.QID return me undefined?  How can I retrieve the total object, i.e. {"QID":"Q2","T":"12"}?

A:

Don't iterate Arrays using for .. in loops.  Use a regular for loop or Array.forEach()*.
That aside, this is not going to be an item in your Array.  You need:
if (data.Questions[item].QID == "Q2") {
    ...
}

Using a regular for loop:
for (var i = 0; i < data.Questions.length; i++) {   
    if (data.Questions[i].QID == "Q2") {   
        ...
    }    
}   

Or, my preferred method, Array.forEach():
data.Questions.forEach(function (item) {
    if (item.QID == "Q2") {
        ...
    }
});

*Older browsers don't natively support Array.forEach(), but you can add it in yourself.  See the compatibility notes for an implementation you can use in your code for older browsers.

