parseInt() [FF, IE 3]

Converts a string to an integer as long as the first character is a number. If the first character is not a number, parseInt() returns NaN (not a number). If the string is a number followed by letters, parseInt() grabs the first set of digits in the string.

Example:

var the_string = "123abc456";
var the_numbers = parseInt(the_string);

The variable the_numbers contains 123.

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.