JavaScript variable split into groups -


this question has answer here:

have var id = "123456789";

how split in groups after each 3 digits??

result must this:

var no1 = 123; var no2 = 456; var no3 = 789; 

if id longer 12, 15 or more digits, should work same!

this can answer, use function per need, output array contains result

function parsedigits() {     var number = 123456789,     output = [],     snumber = number.tostring();      (var = 0, len = snumber.length; < len; += 3) {         output.push(+snumber.charat(i)+snumber.charat(i+1)+snumber.charat(i+2));     }      alert(output);  } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -