JSFiddle - React, Tailwind, and code Playground

JavaScript

// our array
let theArray = [1,1,1,1,1,1,[1,1,1,1,1,1,1,1,[1,1,1,1,1,1]]];

function arraySum(arr) {
  var sum = 0;
  // loop through the array
  for(var i = 0; i < arr.length; i++) {
  // if we come across an array in our array -> we call another brand new instance of the function we're currrently in 
    if(Array.isArray(arr[i])) {
     // because we return the sum at ahe end of the function whatever this new instance of arraySum returns will be added to our sum variable in this instance of the function
     sum+=arraySum(arr[i]); // new seperate of instance of the arraySum function - the original function will pause thill this is done
   // add a number if the item is a number 
  } else if(typeof arr[i]==='number') {
      sum+=arr[i];
    }
  }
  // return the sum 
  return sum; // because this gets returned once the function is complete, all your instances of the arraySum will alway return a number -> sum+=arraySum(arr[i]);
}

console.log(arraySum(theArray));