JavaScript Update specific index in a boolean matrix?

JavascriptWeb DevelopmentObject Oriented Programming

To updates, use the concept of fill() in JavaScript. The fill() method is used to fill the array elements with a static value. Following is the code −

Example

const array= Array(4)
var fillWithTrueValue=array.fill(true);
const matrixWithOnlyBooleanTrue = Array(4).fill(fillWithTrueValue);
console.log(matrixWithOnlyBooleanTrue);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo59.js.

Output

This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo59.js
[
   [ true, true, true, true ],
   [ true, true, true, true ],
   [ true, true, true, true ],
   [ true, true, true, true ]
]
raja
Published on 03-Sep-2020 07:19:41
Advertisements