JavaScript TypedArray fill() method

The JavaScript fill() method is used to fill all the elements of array from a start index to an end index with a static value.

Syntax:

Parameters:

Value(Required): The value to fill the array.

Start(Optional): The index to start filling the array(default is 0).

End(Optional): The index to stop filling the array (default is array.length).

Return value:

This function does not return a new array. Instead of, it transform the array on which this function is applied.

Browser Support:

Chrome45.0
Edge12.0
Firefox31.0
Opera32.0

Example 1

JavaScript TypedArray fill(value) method

Test it Now

Output:

20,20,20,20,20,20,20,20,20,20

Example 2

JavaScript TypedArray fill(value,start) method

Test it Now

Output:

1,2,20,20,20,20,20,20,20,20

Example 3

JavaScript TypedArray fill(value,start,end) method

Test it Now

Output:

1,2,20,4,5,6,7,8,9,10





Latest Courses