Getting the sum of an array

can someone really tell what is wrong with my code ;

function getSum(n){
  //convert interger to string and split;
  const myArray = []
  let string  = n.toString().split("")
 myArray.push(string);


 mySum = myArray.reduce((prev, curr) => prev + curr, 0)
  console.log(mySum)
   
}
 getSum(1234);

Was there any error message when you run this code?

If yes, please paste it here for context.

no error message , it just return on myconsole, the value in the array and added sum of 0…
just like this /// 01,234 ///

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

In your reduce callback, you are hoping to add to numbers. The problem is, in Javascript, when the + operator is used between a string and a number, the number gets coerced into a string, so the + and the two strings are concatenated together. You will need to convert the string into a number to be able to add the two numbers together.

Just to be clear, your myArray is an array of string characters and not an array of numbers.