Q:

Write a JavaScript program to Initialize a two dimension array of given width and height and value

0

Write a JavaScript program to Initialize a two dimension array of given width and height and value.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const initialize_2D_Array = (w, h, val = null) =>
 Array.from({ length: h }).map(() => Array.from({ length: w }).fill(val));

console.log(initialize_2D_Array(2, 2, 0));
console.log(initialize_2D_Array(3, 3, 3));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now