javascript - TypeError: 'undefined' is not an object -


i have dysfunctional javascript program that's been causing me problems. however, throws 1 error don't understand:

typeerror: 'undefined' not object (evaluating 'sub.from.length') 

what i'm trying do, can guess, check length of "from" array in sub dict. here's source code entire function, , here's code of loop think causing error:

console.log(afchelper_ffusubmissions.length); // debugging, returns correct number (var = 0; < afchelper_ffusubmissions.length; i++) { // whole section works fine     var sub = afchelper_ffusubmissions[i];     //console.log("this broken down link",afchelper_submissions[i]);     if (pagetext.indexof(afchelper_ffusections[sub.section]) == -1) {         // has modified section in mean time. skip.         document.getelementbyid('afchelper_status').innerhtml += '<li>skipping ' + sub.title + ': cannot find section. perhaps modified in mean time?</li>';         continue;     }     var text = afchelper_ffusections[sub.section];     var startindex = pagetext.indexof(afchelper_ffusections[sub.section]);     var endindex = startindex + text.length;      console.log(sub);      if (typeof(sub.from) != 'undefined' && sub.from.length > 0) { // ** problem spot?? code added.         (var = 0; < sub.from.length; i++) {             mainid = sub.from[i]['id'];             var sub = afchelper_submissions[mainid]; // , goes on here... 

any ideas great. frankly, can't see why i'm getting typeerror i've explicitly checked type of (typeof(sub.from))...

i'm not sure how check if isn't undefined , @ same time error undefined. browser using?

you check in following way (extra = , making length truthy evaluation)

if (typeof(sub.from) !== 'undefined' && sub.from.length) { 

[update]

i see reset sub , thereby reset sub.from fail re check if sub.from exist:

for (var = 0; < sub.from.length; i++) {//<== assuming sub.from.exist             mainid = sub.from[i]['id'];             var sub = afchelper_submissions[mainid]; // <== re setting sub 

my guess error not on if statement on for(i... statement. in firebug can break automatically on error , guess it'll break on line (not on if statement).


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -