return to homepage

Scripts: Javascript

parseInt()

This function converts a number string into a number/integer that can be added. This sounds odd as all numbers are numbers, but if the number is set in a string, the browser just sees it as a text string e.g.

var aRRay = ['text','number','34',35];

'34' above is seen as a string and 35 above is seen as a number.

To convert text string '34' into just 34 the number, simply use parseInt().

thirtyFour = parseInt(aRRay[2])

or

thirtyFour = parseInt('34')

Once you have converted the string into an integer, you can then manipulate it using maths functions or simply add/subtract it etc.

Added: 15 June, 2006