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
Table of contents Preface 【undo log】 【redo log】 【...
Remount the data disk after initializing the syst...
This article example shares the specific code of ...
Background Replication is a complete copy of data...
1. Monitoring architecture diagram 2. Implementat...
Dockerfile is a text file used to build an image....
This article example shares the specific code of ...
1. First find the Data file on the migration serv...
This article mainly introduces how to implement a...
Recently, when I was using Docker to deploy a Jav...
This article describes how to install opencv with...
Table of contents 1. Browser support 2. export ex...
Modify /etc/my.cnf or /etc/mysql/my.cnf file [cli...
vue-element-admin import component encapsulation ...
Without further ado, let me show you the code. Th...