In order to get the array\'s depth I thought I can use the flat() method like so:
flat()
I think you could use Infinity to flatten your array. MDN gives an example. Not sure how efficient this is though.
const arr4 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]]; arr4.flat(Infinity); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]