Suppose, if you want to create an Array of length ‘5’ and fill it with zeros then we can write the following code.
const n = 5; // Assume 5 as the Length of the array
const array = new Array(n).fill(0);
console.log(array); // Output: [0, 0, 0, 0, 0]
In the same way, If we want to create an Array of length ‘3’ and fill it with the text ‘javascript’ then we can write the following code.
const n = 3; // Assume 3 as the Length of the array
const array = new Array(n).fill('javascript');
console.log(array); // Output: ['javascript', 'javascript', 'javascript']