First time posting. Sorry for bad formatting. I am trying to get my function to work. The current issue is that the recursion stops as soon as the recursive function is called for the first array element. I need it to keep going even after an array is called.
TLDR: I want to flatten the array.
function steamrollArray(arr) {
   var newArr=[];
   //return Array.isArray(arr[2]);
   //takes an array of which some elements will also be arrays and pushes its non-array elements to a new array (newArr)
   function recurseArr(a){
      for (i=0; i<a.length; i++){
         //recursion where you take the array element (also an array) and apply the same function until you get an element
         if(Array.isArray(a[i])){
            //&& i==a.length
            recurseArr(a[i]);
         }
         //case where the original array element is not an array but an element already
         else{
            newArr.push(a[i]);
         }
      }
   }
   //end of recurseArr
  recurseArr(arr);
  return newArr;
}
steamrollArray([1, 2, [2, 3], 2, [[[4]]]]);
desired output: [1,2,2,3,2,4]
 
     
    