"use strict" function fn(a) { let n = 1; while (a.length) { a = [].concat(...a).filter(Array.isArray) ++n } return n } console.log(fn([[[[[]]]],[[]]]));