Devil Raily Devil Raily - 1 year ago 294
Javascript Question

indexOf is not a function

I' am currently working with the following code. In the console it's throwing

Uncaught TypeError: TotalAccountBalance.indexOf is not a function

I don't know what else to do. Searching didn't help much.

var CurrentPreservedBalance, CurrentGeneralAccountBalance, TotalAccountBalance;
CurrentPreservedBalance = '20.56';
CurrentGeneralAccountBalance = '20.56';
if( CurrentPreservedBalance && CurrentGeneralAccountBalance ){
TotalAccountBalance = +CurrentPreservedBalance + +CurrentGeneralAccountBalance;
console.log( TotalAccountBalance.indexOf('.') );
} else {

Answer Source

indexOf() is a method of Strings, not Numbers.

console.log( TotalAccountBalance.toString().indexOf('.') );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download