Array.prototype.fill >= 0.1.3

Purpose

Fill all the elements of the array from a start index to an end index with a static value

Syntax

Array#fill ( ObjectvalueNumberstart= 0Numberend= this.length );

Parameters

value

Value to fill an array with

start

Start index

end

End index (non-inclusive)

Return values

Examples

Fill an array


var arr = new Array(10);
>>> [undefined × 10]

arr.fill(1);
>>> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

Fill an array starting at a given index

var arr = new Array(10);
>>> [undefined × 10]

arr.fill(1);
>>> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

arr.fill(2, 2)
>>> [1, 1, 2, 2, 2, 2, 2, 2, 2, 2]

Fill an array starting at an index and until an index

var arr = new Array(10);
>>> [undefined × 10]

arr.fill(1);
>>> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

arr.fill(3, 2, 4)
>>> [1, 1, 3, 3, 1, 1, 1, 1, 1, 1]

Comments

Milan

I located your website from Google as well as I have to state it was a wonderful discover. Thanks!

Shannon

Could you inform me what style are you making use of on your web site? It looks good.

Deandre

Have you ever before had issues with your hosting?

I'm open for suggestions as my webhost is dreadful now.

Willian

Have you ever had troubles with your hosting? I'm open for suggestions as my webhost is terrible now.