I think this would be a great example to use the new flat
function in arrays
refer [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat]
let a = [[1],[2,3,['abc']],[5,[6,['def']]]]
a = a.flat(Infinity); // since the nesting may be highly deep
You can use a recommended polyfill since the browser support is not very high.
Alternatives are to use reduce and concat, which is explained in the link above.
//to enable deep level flatten use recursion with reduce and concat
var arr1 = [1,2,3,[1,2,3,4, [2,3,4]]];
function flattenDeep(arr1) {
return arr1.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val), []);
}
flattenDeep(arr1);// [1, 2, 3, 1, 2, 3, 4, 2, 3, 4]