JQBolo JQBolo - 1 month ago 5
jQuery Question

Jquery Object array accessing in $.each loop

I'm tying to access a specific value in an object array, but ONLY if

a) a specific user ID value is stored in

response.feed.data


b) the key
story
exists

I've been playing around with $.each loops but I'm still sort of confused about accessing values inside nested objects, I'm doing SOMETHING wrong because the value is coming back as undefined no matter how I try to access it, [index].story currently just logs the same array of objects stored in
response.feed.data


$.each(response.feed.data, function(key, index){
if([index].id == "USER ID"){
if([index].story){
console.log([index].story);
}

}

Answer

index will store the position of that specific key inside response.feed.data. So you can't access index.story. Instead you will have to access it from key if its present inside key.