Javatpoint Logo
Javatpoint Logo

JavaScript Array fill() method

The JavaScript array fill() method fills the elements of the given array with the specified static values. This method modifies the original array. It returns undefined, if no element satisfies the condition.

Syntax

The fill() method is represented by the following syntax:

Parameter

value - The static value to be filled.

start - It is optional. It represents the index from where the value starts filling. By default, it is 0.

end - It is optional. It represents the index where the value stops filling. By default, it is length-1.

Return

The modified array.

JavaScript Array fill() method example

Let's see some examples of fill() method.

Example 1

Here, we will provide only the value to be filled.

Test it Now

Output:

Bootstrap,Bootstrap,Bootstrap

Example 2

In this example, we will also provide the starting index.

Test it Now

Output:

AngularJS,Bootstrap,Bootstrap

Example 3

In this example, we will also provide start and end index.

Test it Now

Output:

Bootstrap,Bootstrap,JQuery

Next TopicJavaScript Array




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA