Write a function in JavaScript to calculate the sum of a given array of numbers.
user
function sumOfArray(arr){
  var sum = 0;
  for(var i=0;i<arr.length;i++){
    sum+=arr[i];
  }
  return sum;
}
assistant