create 2d array in javascript filled with 0
function zeros(dimensions) {
var array = [];
for (var i = 0; i < dimensions[0]; ++i) {
array.push(dimensions.length == 1 ? 0 : zeros(dimensions.slice(1)));
}
return array;
}
> zeros([5, 3]);
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
Also in JavaScript:
- javascript replace all occurrences of string
- mapstatetoprops redux
- index and id together angularjs
- how to get today date in javascript
- js ceil
- get a user input react
- jQuery UI Sortable, then write order into a database
- $.ajax javascript
- javascript check if array is not empty
- date picker type react
- w3 js resize event
- angular
- Create a node in the Node Editor or Hypershade, press the ____ and type into search bar:
- parsefloat jquery
- login condition if and else in router dom of react jsx
- javascript redirect to another page
- javascript exercism.io bob solution
- convert number to indian rupee format in javascript
- jquery check if clicked outside div
- js for loops
- how to know how many pixels of page be scrolled javascript
- start react native
- javascript round to 2 digits
- javascript how to sort variables by user input