flat Array Method | JavaScript Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the array flap method creates a new array with all the sub arrays elements concatenated into it it was recursively up to the specified depth let's see in code how that works we have here an array which has an array inside of an array inside of an array inside of an array so we have multiple depths of disarray but we want at the end to have something like this 1 2 3 4 so we want to have a one-dimensional array we can do so with the array that flat method let's store the result array dot flat and let's see what we have now cause that flog result all right good you can see that it removed one array but we still have an array inside of an array here and why is that that's because we haven't provided a depth here to the flat method telling how deep it should go inside the nest of the race by default value is 1 but if we provide here 3 which is the level we have and save now you can see that we get the array we wanted what happens now if we add here 5 inside another array well then we're going to get that inside the Mon array so what if we want to have the array flat method to work or an infinite number of nested arrays well for that we can pass here infinity and this will work now for no matter how many arrays we have nested inside of an array I hope you enjoyed this tutorial and I'll see you in the next one bye [Music] you
Info
Channel: Florin Pop
Views: 3,598
Rating: 4.9523811 out of 5
Keywords: javascript, javascript tutorial, javascript tutorial for beginners, array method, javascript arrays, higher order function, learn javascript, javascript array methods, flat, flatten array, javascript flat, javascript flat array, flat array method, learn flat
Id: d3TJbWvfSgw
Channel Id: undefined
Length: 2min 2sec (122 seconds)
Published: Fri Apr 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.