Loop - forBasic use of for loopfor loop syntax : repeatedly execute code Advantages : Write the declaration starting value, loop condition, and change value together, making it clear at a glance for (variable starting value; loop condition; variable update) { Loop Body} The difference between for loop and while loop:
Exit the loopEnd of loop:
Nested loopsA loop inside another loop, usually used in a for loop for (variable starting value; loop condition; variable update) { for (variable starting value; loop condition; variable update) { Loop Body} } ArraysWhat is an array?Array is a data type that can store data in sequence. Basic use of arraysDeclaration Syntax let array name = [data1, data2, ..., datan] 1The array is saved in order, so each data has its own number 2. Numbering in computers starts at 0, and so on 3. In an array, the number of data is also called index or subscript 4. Arrays can store any type of data Value Syntax Array name[subscript] 1. Get data by subscript 2. What type of data is retrieved? Then access it based on the characteristics of that type. Some terminology
Array name.length Iterating over an arrayUse a loop to access each element in the array, usually using a for loop for (let i = 0; i < array name.length; i++) { Array name[i] } Manipulating ArraysThe essence of an array is a collection of data. To operate data is nothing more than adding, deleting, modifying and checking syntax. 1. Check: query array data, or we call it access array data array [subscript] 2. Change: Reassign array [subscript] = new value 3. Increase: add new data to the array
4. Delete: Delete the data in the array
Add new data to the array
arr.push(element 1, element 2, ..., element n) arr.unshift(element1, element2, ..., elementn) Deleting elements from an array
arr.pop() Array.shift() method removes the first element from an array and returns the value of that element. arr.shift() Array. splice() method deletes the specified element (key point) arr.splice(start, deleteCount) arr.splice (starting position, delete several elements) start Starting position: Specify the start position of the modification (counting from 0) Indicates the number of array elements to be removed Optional. If omitted, the default is to delete from the specified starting position to the end Deleting elements: Random draw, the winning user needs to be deleted from the array, and duplicate draws are not allowed Click the Delete button and the related data will be deleted from the product data SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Docker overlay realizes container intercommunication across hosts
As you build and scale your Django applications, ...
Table of contents 1. Simple mounting of persisten...
Vue+js realizes the fade in and fade out of the v...
Table of contents 1.MySQL adds or subtracts a tim...
XML/HTML CodeCopy content to clipboard < div c...
When the user's home directory becomes larger...
1. Introduction Image maps allow you to designate...
1. Command Introduction The ln command is used to...
1. Enter the Docker official website First, go to...
1. Download MySQL Log in to the MySQL official we...
Docker usage of gitlab gitlab docker Startup Comm...
Table of contents Slots What are slots? Slot Cont...
Table of contents Install Dependencies Install bo...
After installing Docker on the Linux server, Pull...
Preface If you use the overflow: scroll attribute...