How to convert a 2D array to a 1D array in Node.js

1 Answer

0 votes
const arr2d = [ 
    [ 3, 7, 1, 4 ], 
    [ 3, 8, 0, 2 ],
    [ 9, 2, 6, 5 ] 
];
 
const arr = arr2d.flat();
 
arr.forEach(n => {
    process.stdout.write(n + "\t");
});
 
  
   
/*
run
  
3	7	1	4	3	8	0	2	9	2	6	5	
   
*/

 



answered Aug 14, 2024 by avibootz

Related questions

...