Type Error with array spread

Tell us what’s happening:
it gives a type error and I don’t know why;

  **Your code so far**

function steamrollArray(arr) {
const newArr=[];
if(!Array.isArray(arr)){
  return arr;
}
for(let i = 0 ; i < arr.length ; i++){
  if(Array.isArray(arr)){
  newArr.push(...steamrollArray(arr[i]))};
  
}
console.log('here')
return newArr;
}

steamrollArray([1, [2], [3, [[4]]]]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36

Challenge: Steamroller

Link to the challenge:

In your for-loop you are checking if arr is an array - instead of checking if arr[i] is an array.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.