JavaScript Update specific index in a boolean matrix?


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

Updated on: 03-Sep-2020

148 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements