Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

indexOf is not a function

Tags:

javascript

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');
    }
like image 332
Devil Raily Avatar asked Oct 02 '16 20:10

Devil Raily


People also ask

What is the function of indexOf?

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.

Why indexOf is not working JavaScript?

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).

How do I fix uncaught Typeerror e indexOf is not a function?

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.

What is the function of the indexOf () in arrays?

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.


1 Answers

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

console.log( TotalAccountBalance.toString().indexOf('.') );
like image 184
Andy Ray Avatar answered Nov 15 '22 16:11

Andy Ray