JavaScript Flatten Nested Arrays with Recursion

preview_player
Показать описание

Комментарии
Автор

Thanks for this! I'm not quite so familiar with recursion at this point, but already I find it beautiful.

blaketruelove
Автор

This is exactly what i was looking for. Thanks this is going to be very helpfull!!!

cristhianmorales
Автор

Great video! Super helpful to watch you work through it without cutting away...

Ombibulous_Bluegrass
Автор

Nice. Thank you that was useful to me!

JulienReszka
Автор

why do we concat? why cant we just call flatten(value) if its aray?

soulrider
Автор

I get what's going on but probably need a more written out detailed step by step picture to see the mechanics of things if ya'll know what I mean

rogerh
Автор

Without concat :
const data = [[0, 1, 2], [3, 4, 5, [0, 0, 0, [6, 6, 6]]], [6, 7, 8]];
let flattenArr = [];
const flatten = (data) => {
if(Array.isArray(data)) {
data.forEach(item => flatten(item));
} else {
flattenArr.push(data);
}
return flattenArr;
}
console.log(flatten(data));

victoreliot