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');
}
The indexOf() method returns the position of the first occurrence of a value in a string. The indexOf() method returns -1 if the value is not found. The indexOf() method is case sensitive.
indexOf does work and does do what you say it does. If you're getting this error, it might mean you've mixed up source and destination (the array before the dot is the one being searched), or you have another subtle programming error (like you aren't comparing the array you think you're comparing).
This is because indexOf was not supported in 3.3. 1/jquery. min. js so a simple fix to this is to change it to an old version 2.1.
The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
indexOf()
is a method of Strings, not Numbers.
console.log( TotalAccountBalance.toString().indexOf('.') );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With