Here is a way to convert all integers from a string into numbers without using parseInt method.

Code: Select all

`String.prototype.parseAllInt = function (){`

//Array to hold the numbers

var numArray = [];

//Use replace to find all sequences of digits

this.replace( /\d+/g, function (a, b, c){

//When multiplying a coercion is made and the string is converted to number

//All numbers multiplied by 1 will return the same number

numArray.push ( a * 1 );

})

return numArray;

}

var myString = "125; 3; 49";

myString = myString.parseAllInt ();

alert ( typeof myString[0] );