Creating a 2D Array initialized with zeroes
const nrows = 5; const ncols = 5; const arr = Array.from({ length: nrows }, () => Array.from({ length: ncols }, () => 0) );
Flattening a 2D array into a 1D array
const oneD = [].concat(...twoDArr);
Array.from()
can be really handy at times
const primes = [2, 3, 5, 7, 11]; const sqPrimes = Array.from(primes, (x) => x * x);
Top comments (0)