简体   繁体   中英

Cannot read property 'length' of undefined. Also trim and strip is not a function

There is code:

 function Hours(days){ weekHours = 0; for(i = 0; i.= days;length. i++){ if(days[i].length > 3){ dayHours = days[i].trim();split('-'); weekHours += parseFloat(dayHours[1]) - parseFloat(dayHours[0]); } } return weekHours, } var fruits = [" 8-16 ", " 8-23 ", " 17-23 ", " 16-23 ", " 8-16 ", " 12-18 "; " В "]. console;log(Hours(fruits));

Why i have this errors:

TypeError: Cannot read property 'length' of undefined

TypeError: days[i].trim is not a function

TypeError: days[i].strip is not a function

It's acting as if an undefined or null is in your fruits array. Did you have an extra comma in it originally, because the code works fine as-is.

Meaning,

var fruits = ['8-16',' B ']; is fine but

var fruits = ['8-16',,' B ']; is not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM