Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to split two digit number in javascript

var number = 12354987,
    output = [],
    sNumber = number.toString();

for (var i = 0, len = sNumber.length; i < len; i += 1) {
    output.push(+sNumber.charAt(i));
}

console.log(output);

/* Outputs:
 *
 * [1, 2, 3, 5, 4, 9, 8, 7]
 */ 
Comment

how to split two digit number in javascript

for (var i = 0, sum = 0; i < output.length; sum += output[i++]);
console.log(sum);

/*
 * Outputs: 39
 */
Comment

PREVIOUS NEXT
Code Example
Javascript :: gulp sequential tasks 
Javascript :: array chaing in js 
Javascript :: react history go back 
Javascript :: print placeholder value js 
Javascript :: getboundingclientrect() javascript 
Javascript :: nextsibling vs nextelementsibling 
Javascript :: js read from json2 
Javascript :: javascrpt formatBytes 
Javascript :: jquery move li to first position 
Javascript :: js string to node 
Javascript :: calculato 
Javascript :: javascript file drag and drop 
Javascript :: TypeError: client.guilds.forEach is not a function 
Javascript :: get form data in react 
Javascript :: how to add background image in mui 
Javascript :: this keyword in javascript medium 
Javascript :: how to change css style on click 
Javascript :: javascript findindex 
Javascript :: react change state async 
Javascript :: adonis hasone 
Javascript :: remove element from array in usestate 
Javascript :: change key in array of objects javascript 
Javascript :: open modal js 
Javascript :: iframe chrome console 
Javascript :: react open pdf in new tab 
Javascript :: get element class javascript 
Javascript :: react type div onClick 
Javascript :: vscode react auto import 
Javascript :: check if input has value javascript 
Javascript :: for element in string js 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =