The fill()
method for arrays in Javascript allows an array to be filled with certain values over certain indices ranges.
Examples
const arr1 = [0, 1, 2, 3];
// Fill the array with 2, from positions 1-3
console.log(arr1.fill(2, 1, 3)); //[0, 2, 2, 3]
// Fill the array with 0 from position 2
console.log(arr1.fill(0, 2)); //[0, 1, 0, 0]
//Fill the array with 3 for all elements
console.log(arr1.fill(3)); //[3, 3, 3, 3];