JSFiddle - React, Tailwind, and code Playground
by Alexey Demin
JavaScript
class TwoDimensionalArray {
constructor(firstDimMaxLength, secondDimMaxLength) {
this.firstDimMaxLength = firstDimMaxLength;
this.secondDimMaxLength = secondDimMaxLength;
this.arr = [[]];
}
push(firstDimIndex, secondDimIndex, value) {
if((firstDimIndex + 1) > this.firstDimMaxLength || (secondDimIndex + 1) > this.secondDimMaxLength) {
throw "Index out of range";
}
this.arr[firstDimIndex][secondDimIndex] = value;
}
getArr() {
return this.arr;
}
}
var twoDimArr = new TwoDimensionalArray(2, 4);
twoDimArr.push(1, 3, true);
console.log(twoDimArr.getArr());