javascript - TypeError: Cannot read property 'indexOf' of undefined - Stack Overflow

Node is giving this error while checking the occurrence of a substring:TypeError: Cannot read property

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745211326a4616855.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信