const flatten = (arr) => arr.reduce((acc, item) => Array.isArray(item) ? acc.concat(flatten(item)) : acc.concat(item), []) let arr = [1, [2, [3, 4]]]; console.log(flatten(arr))