Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove unnecessary arrays within arrays after map

After a mapping an array 3 times i hva gotten this result:

[ [ [ [11], [22], [123], [asd] ] ] ]

How do i clean this array to become like so:


[ [11], [22], [123], [asd] ] 

cant remember how to do this or word this problem to get a answer. Thanks!!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use Array.prototype.flat method to flatten your array.

If you know exactly how many levels you need to flatten, you can pass in that as an argument to the method.

In your case you can use arr.flat(2)

let arr = [ [ [ [11], [22], [123]] ] ];
console.log(arr.flat(2));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading