js fill array code example

Example 1: javascript fill array

const fill = new Array(5).fill(0)
console.log(fill) // [ 0,0,0,0,0]

Example 2: fill array with values javascript

let filledArray = new Array(10).fill({'hello':'goodbye'});

Example 3: js clone array

var clone = myArray.slice(0);

Example 4: array fill

new Array(5).fill('element')
// ["element", "element", "element", "element", "element"]

Example 5: js create array with default value

Array(24).fill(0)

Example 6: js fill array with count elements

Array(3).fill(4);                // [4, 4, 4]