Preface: We know a lot about how to initialize arrays, but after initializing the array, each element in the array defaults to an 1. fill() syntax Use the syntax:
2. Use of fill()// When a single parameter is passed, the method fills the entire array with the value of that parameter var arr1 = new Array(5) console.log(arr1.fill(1)); //[1,1,1,1,1] var arr2 = [1, 2, 3, 4] console.log(arr2.fill(0)); //[0,0,0,0] // When two parameters are passed in, the first parameter is the element to be filled, and the second is the starting position of the filled element var arr3 = [0, 1, 2, 3, 4, 5, 6] console.log(arr3.fill(1, 3)); //[0,1,2,1,1,1,1] // When three parameters are passed in, the first parameter is the element to be filled, the second and third parameters refer to the starting and ending positions of the filled element respectively, and the ending position element is not modified var arr4 = [0, 1, 2, 3, 4, 5] console.log(arr4.fill(1, 3, 5)); //[0,1,2,1,1,5] //If the starting position or ending position provided is a negative number, the length of the array will be added to them to calculate the final position. For example, a starting position of -1 is equivalent to array.length-1 var arr5 = [0, 1, 2, 3, 4, 5] console.log(arr5.fill(1, -3));//[0,1,2,1,1,1] var arr6 = [0, 1, 2, 3, 4, 5] console.log(arr6.fill(1, 3, -2));//[0,1,2,1,4,5] 3. SummaryThe above is the full content of this article. I hope it can bring some help and progress to the readers. If it is convenient, please follow me. Xiaobai’s Growth Path will continue to update some common problems and technical points in work. This is the end of this article about the js array You may also be interested in:
|
<<: Delete the image operation of none in docker images
>>: mysql8.0.23 msi installation super detailed tutorial
Table of contents 1. Learn to return different da...
From the tomcat configuration file, we can see th...
<br />Original text: http://andymao.com/andy...
Borrowing Constructors The basic idea of this t...
When we create a page, especially a homepage, we ...
This article lists some tips and codes about form...
Table of contents 1. Function signature 2. Functi...
Table of contents 1. Initialize the array 2. Arra...
This article example shares the specific code of ...
Introduction The Docker community has created man...
js execution Lexical analysis phase: includes thr...
Table of contents Installing the SDK Managing loc...
Table of contents When setting up a MySQL master-...
Today, when verifying the concurrency problem of ...
To display the JSON data in a beautiful indented ...