Let's suppose I have an integer value as
const num = 123456789
and I want to print the sum of these no. in react as 1+2+3+4+5+6+7+8+9 = 45
expect output = 45
approach I am following is as follows
const [total, setTotal] = useState(0);
const num = 123456789
for (const element of num ) {
setTotal(total + element)
}
console.log(total)
Output I am getting is : 01
Need your help here please!