Thursday, October 5, 2023
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  138] [ 3]  / answers: 1 / hits: 26691  / 15 Years ago, fri, february 27, 2009, 12:00:00

Firstly - my description ;)



I've got a XmlHttpRequests JSON response from the server.
MySQL driver outputs all data as string and PHP returns it as it is, so any integer is returned as string, therefore:



Is there any fast alternative (hack) for parseInt() function in JS which can parse pure numeric string, e.g.



var foo = {bar: 123};
...
foo.bar = parseInt(foo.bar); // (int) 123

More From » mysql

 Answers
78

To convert to an integer simply use the unary + operator, it should be the fastest way:



var int = +string;


Conversions to other types can be done in a similar manner:



var string = otherType + ;
var bool = !!anything;


More info.


[#99916] Saturday, February 21, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
haleeg

Total Points: 703
Total Questions: 100
Total Answers: 98

Location: Dominica
Member since Sat, Nov 5, 2022
12 Months ago
;