Easy Tutorial
❮ Prop Password Form Prop Style Borderleftcolor ❯

JavaScript fill() Method

JavaScript Array Object

Example

Fill an array with a fixed value:

fruits output result:

tutorialpro,tutorialpro,tutorialpro,tutorialpro

Definition and Usage

The fill() method is used to replace array elements with a fixed value.


Browser Support

The numbers in the table indicate the first browser version that fully supports the method.

Method
fill() 45.0 12.0 31.0 7.1 32.0

Note: The fill() method is not supported in IE 11 and earlier versions.


Syntax

array.fill(value, start, end)

Parameters

Parameter Description
value Required. The value to fill with.
start Optional. The start position.
end Optional. The end position (default is array.length).

Technical Details

| Return Value: | Array | | JavaScript Version: | ECMAScript 6 |

More Examples

Example

Fill "tutorialpro" into the last two elements of the array:

Output result:

Banana,Orange,tutorialpro,tutorialpro

JavaScript Array Object

❮ Prop Password Form Prop Style Borderleftcolor ❯