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
After installing MySQL, enter mysql -u root -p in...
Table of contents Event Loop miscroTask (microtas...
I don't expect to be an expert DBA, but when ...
Busybox: A Swiss Army knife filled with small com...
How to make a simple web calculator using HTML, C...
Preface Due to the weak typing of JS, loose writi...
The usage format of the mysqladmin tool is: mysql...
In order to express the deep condolences of peopl...
Today, in the practice of vue3+vite project, when...
MySQL is divided into installation version and fr...
Preface The simple understanding of MySQL permiss...
This article shares the specific code of Vue+ssh ...
If a form field in a form is set to disabled, the ...
Block element HTML tag classification details * a...
Table of contents 1. Introduction 2. Component De...