javascript
add sum of numbers of given numbers
Input - let a = 345;
let a = 345;
const sum = a.toString().split('').reduce((acc, curr) => {
return acc + parseInt(curr);
}, 0);
console.log(sum); // Output: 12
Output
Output - 12
Was this helpful?
Similar Posts
- Get total sum of specif attribute inside of array of objects
- Get the sum of array values using Javascript - Solved
- sum of number - info inte qns
- Remove items starting from last untill given condition is false Lodash
- Remove items begin from start until given condition is false Lodash
- Check if given value is an array in Javascript
- Get year from given date using Javascript