var arr = [{name: 'yy'}, [{name: 'gg'}, [{name: 'hh'},[{name:'lw'}]]], 1, 2]
console.log(arr.flat(3))
Array.prototype.myFlat = function(deep=1){
let arr = this.slice();
let flatArr = [];
for(let i=0; i< arr.length; i++){
if(Object.prototype.toString.call(arr[i]) === '[object Array]'){
if(deep == 1){
for(let j=0; j< arr[i].length; j++){
flatArr.push(arr[i][j])
}
}else {
flatArr = flatArr.concat(arr[i].myFlat(deep-1))
}
}else {
flatArr.push(arr[i])
}
}
return flatArr;
}
console.log(arr.myFlat(1))
// console.log(arr)
console