I have a JS function that needs to have object as its parameter. I want to get the property and values of the object. Following is the list of JS object in my program:
var a =[{'Jan':1555},{'Feb':456},{'Mar':987},{'Apr':768}];
As expected to get the property and values one can use for loop here like below:
for(var i=0;i<a.length;i++){
for(var j in a[i]){
console.log(j); // Here it returns the property correctly
console.log(a[i].j); //Returns Error here ie returns undefined
}
}
Now above line console.log(a[i].j) returns undefined values while if manually checking the list like a[0].Jan I get 1555 , a[1].Feb returns 456 and so on. Why is this so? Please correct the code if I am wrong as i am new in JS.