OneCompiler

Array Fill method

114

// Array fil method if you want to fill some same value in empty array so use can easy to use this array fill method

const myarr = new Array(10).fill(0)
console.log('myarr--->', myarr);

// output :
// [0,0,0,0,0,0,0,0,0,0]

// if we want to change some thing in array we can also use fill method

const myArr = [1, 2, 3,4, 5, 6]
myArr?.fill(0, 1, 4)
console.log('myarr---->', myArr);