Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

creating 2d array in javascript

var [r, c] = [5, 5]; 
var m = Array(r).fill().map(()=>Array(c).fill(0));
Comment

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]]
Comment

PREVIOUS NEXT
Code Example
Javascript :: round value down html 
Javascript :: round down js 
Javascript :: apply() js 
Javascript :: how to sepaarte text in object javascript 
Javascript :: react usestate 
Javascript :: node express dynamic route and error handler 
Javascript :: find second smallest number in array 
Javascript :: google translate javascript 
Javascript :: Different views for Desktop and mobile Angular 
Javascript :: how to change created_at format with javascript rails 
Javascript :: how to implement certain actions after setstate in react hooks 
Javascript :: hover javascript 
Javascript :: change base js 
Javascript :: JavaScript do...while Loop 
Javascript :: JavaScript try...catch Statement 
Javascript :: angular hash sign in url 
Javascript :: url fetch app pass payload and headers 
Javascript :: cypress element length 
Javascript :: xor operator js 
Javascript :: how to connect socket in react js 
Javascript :: datatable sAjaxSource get output 
Javascript :: javascript audio navigator audio stream 
Javascript :: string contains js 
Javascript :: how to assign char in a string javascript 
Javascript :: index and id togtgher angularjs 
Javascript :: calculate 7 days in javascript countdown 
Javascript :: javascript countdown timer including days 
Javascript :: set json column as index pandas dataframe 
Javascript :: how to setup material-table in react 
Javascript :: same file select angular second time not selected 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =