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 isundefined
. – Soubhik Mondal Commented May 1, 2016 at 2:08 -
That means that
project
doesn't have awithdrawal
property. (Or it does have awithdrawal
property, but that property's value isundefined
.) – nnnnnn Commented May 1, 2016 at 2:09 -
1
you have a typo
user.ueamil
– Dave Pile Commented Nov 20, 2016 at 8:21
1 Answer
Reset to default 2The 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.