Steamroller help with regex skipping a number

Tell us what’s happening:
I’ve added the explanation with my code, basically the regex test inside my for loop is skipping a number and I’ve tried running the code without mutating anything so I know it’s not that. I don’t know why it’s skipping a number.

Your code so far


//Goal of the code is to return a "flat" array from the nest array given as the argument
function steamrollArray(arr) {

let newArr = arr.toString()
.replace(",,", ",")
.replace("[object Object]", "{}").split(","); //I turned the whole thing into string to flatten most of it, most of the work is done

console.log(newArr); //returns [ '1', '2', '3', '4', 'a', 'b', '1', '3', '4', '1', '{}', '3', '4' ] I logged to see the results, no problem here, all elements are separated by a comma

let regex = /\d/g; //I need to turn the numbers back into Numbers from a stringy number so I used this regex to test

for (let i = 0; i < newArr.length; i++){
if (regex.test(newArr[i])){
console.log(newArr[i]); // returns 1 3 1 4 3 (it skips some numbers) it keeps alternating, it should return 1, 2 ,3, 4, 1, 3, 4, 1 ,3, 4

newArr[i] = Number(newArr[i]); //when I cancel this and just stick with the log, it still skips which means it's not a mutation issue
}
}
return newArr; //[ 1, '2', 3, '4', 'a', 'b', 1, '3', 4, '1', '{}', 3, '4' ] you can see some of the numbers are still strings.
}

steamrollArray([1, [2], [3, [[4]]], [[["a"]], [["b"]]], [1, [], [3, [[4]]]], [1, {}, [3, [[4]]]]]);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller/

Don’t use the global flag.