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

How can I convert an array with two sets of brackets to have only one set of brackets?

how can I convert [[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "]] to

[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "]?

I pushed an array to another, now I want to remove outer brackets from ii .

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

I’m looking for a method.

let ii :any[]=[];
const i =  ' '.repeat(10) ;
const d =  i.split('')   ; 
const aa=ii.push(d);
console.log(ii,ii.length);
console.log(d,d.length ); 

>Solution :

Modern javascript enviroments support the flat() method.

const flatData = [["a", "b", ["c", "d"]]].flat(2)
console.log(flatData)
// ["a", "b", "c", "d"]

The number you can optionally pass to flat() is the number of levels to flatten.

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