Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

What's The REAL Secret To First Date Success With a Woman? Click Here To Find Out

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

29,372 questions

38,322 answers

573 users

How to create a two dimensional (2D) array and initialize the array with specific number in JavaScript

1 Answer

0 votes
const rows = 3;
const cols = 4;
const arr = new Array(rows).fill(new Array(cols).fill(-1));

console.log(arr);




/*
run:

[ [ -1, -1, -1, -1 ], [ -1, -1, -1, -1 ], [ -1, -1, -1, -1 ] ]

*/

 


Protect Your Privacy - Download VPN


answered Feb 15 by avibootz
...