Devil Raily Devil Raily - 2 months ago 18
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 {
$('#total-fnpf-account-balance').val('$0.00');
$('#total-account-balance').val('$0.00');
}

Answer

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

console.log( TotalAccountBalance.toString().indexOf('.') );
Comments