admin管理员组

文章数量:1415111

Node is giving this error while checking the occurrence of a substring:

TypeError: Cannot read property 'indexOf' of undefined'

var withdraw = project.withdrawal;
                var uemail = user.eamil;
                var ans = withdraw.indexOf(uemail) > -1;

Node is giving this error while checking the occurrence of a substring:

TypeError: Cannot read property 'indexOf' of undefined'

var withdraw = project.withdrawal;
                var uemail = user.eamil;
                var ans = withdraw.indexOf(uemail) > -1;

Share Improve this question edited Aug 17, 2020 at 18:36 xKobalt 1,5082 gold badges14 silver badges20 bronze badges asked May 1, 2016 at 2:05 Syed Usman TariqSyed Usman Tariq 211 gold badge1 silver badge3 bronze badges 4
  • 1 can you console.log(withdraw) and show result... – uzaif Commented May 1, 2016 at 2:07
  • Your withdraw variable is undefined. – Soubhik Mondal Commented May 1, 2016 at 2:08
  • That means that project doesn't have a withdrawal property. (Or it does have a withdrawal property, but that property's value is undefined.) – nnnnnn Commented May 1, 2016 at 2:09
  • 1 you have a typo user.ueamil – Dave Pile Commented Nov 20, 2016 at 8:21
Add a ment  | 

1 Answer 1

Reset to default 2

The variable withdraw is most likely undefined. Can you default it to an empty string with:

var withdraw = project.withdrawal || "";

That should avoid the error, but it might be better to check if there's another error causing withdrawal to be undefined.

本文标签: javascriptTypeError Cannot read property 39indexOf39 of undefinedStack Overflow