Home » JavaScript TypedArray fill() Method

JavaScript TypedArray fill() Method

by Online Tutorials Library

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:

Chrome 45.0
Edge 12.0
Firefox 31.0
Opera 32.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  

You may also like