const arr = [1, [2, [3, 4]], 5];
function flattenArr(arr){
let fArr = [];
for(const a of arr){
if(Array.isArray(a)){
fArr = fArr.concat(flattenArr(a))
} else{
fArr.push(a);
}
}
return fArr;
}
const result = flattenArr(arr);
console.log(result,'---result')
To embed this project on your website, copy the following code and paste it into your website's HTML: