Inadvertently see fill this method, some puzzled, at first thought is someone else's custom method, later discovered that originally is not, JavaScript inside is really has this method, therefore specially studied under.
The fill () method is used to replace elements in the array with a fixed value. The fixed value can be a letter, a number, a string, an array, and so on. The Fill () method also has two optional parameters that indicate the starting and ending positions of the fill.
For example, replace the elements in the array with numbers.
var arr3 = [12,23,34,45,56];arr3.fill (123); Console.log (ARR3) // [ 123,123,123,123,123]
Replace the elements in the array with strings.
var arr3 = [12,23,34,45,56];arr3.fill ("Hello"); Console.log (ARR3) // [" Hello "," Hello "," Hello "," Hello "," Hello "]
Use an array to replace the elements in the array.
var arr3 = [12,23,34,45,56];arr3.fill ([123]); Console.log (ARR3) // [ [123], [123], [123], [123], [123]]
Specifies the starting and ending positions of the substitution.
var arr3 = [12,23,34,45,56];arr3.fill (1234,1,3); Console.log (ARR3) // [ 1234, 1234 , A.
1 represents the starting position of the substitution, and 3 indicates the end position of the substitution, and it can be seen that the element containing index 3 is not included.
Full usage: Fill (value,start,end) where the 2nd, 3 parameters are optional. Indicates the start and end position of the substitution (note: The element containing the end position itself is not included)
Note: the fill () method is not supported for IE11 and earlier versions.
The fill () method of JavaScript