MindMap Gallery JS Basics Day3
This is a thinking guide about JS basics Day 3, including loops, Arrays and other knowledge points. Hope this mind map helps you!
Edited at 2024-01-18 10:22:04This is a mind map about bacteria, and its main contents include: overview, morphology, types, structure, reproduction, distribution, application, and expansion. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about plant asexual reproduction, and its main contents include: concept, spore reproduction, vegetative reproduction, tissue culture, and buds. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about the reproductive development of animals, and its main contents include: insects, frogs, birds, sexual reproduction, and asexual reproduction. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about bacteria, and its main contents include: overview, morphology, types, structure, reproduction, distribution, application, and expansion. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about plant asexual reproduction, and its main contents include: concept, spore reproduction, vegetative reproduction, tissue culture, and buds. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about the reproductive development of animals, and its main contents include: insects, frogs, birds, sexual reproduction, and asexual reproduction. The summary is comprehensive and meticulous, suitable as review materials.
JS Basics Day3
Loop-for
for loop-basic use
Function: Repeated execution of code
Advantages: writing the starting value, loop condition, and change value together makes it clear at a glance. It is the most commonly used loop form.
Syntax: for (variable starting value; termination condition; variable change) {loop body}
exit loop
continue: exit this loop, generally used when excluding or skipping an option
break: Exit the entire for loop. It is generally used when the result has been obtained and subsequent loops are not needed.
learn
while(true) to create an "infinite" loop, you need to use break to exit the loop
for(;;) is used to construct an "infinite" loop, and break is also needed to exit the loop.
Nested loops
Syntax: for (external declaration of a variable that records the number of loops; loop condition; changed value) {for (internal declaration of a variable that records the number of loops; loop condition; changed value) {loop body}}
A loop inside a loop, usually used for for loops
array
What is an array
Array: A data type that can store data in order
Basic usage of arrays
Declaration syntax
let array name = [data1, data2,..., datan]
let arr = new Array (data 1, data 2, ..., data n)
Arrays are stored in order, and each data has its own number
Numbering starts from 0
In an array, the number of the array is also called a subscript or index.
Arrays can store any type of data
Value syntax: array name [subscript]
the term
Length: The number of data in the array, obtained through the length attribute of the array
Subscript: the number of the data in the array
Element: Each data stored in the array is called an array element.
Traverse array
Use a loop to access each element in the array, usually using a for loop
Syntax: for (let i = 0;i<array name.length;i){document.write(array name[i])}
Operate array
Query array data
array[subscript]
reassign
array[subscript] = new value
Add new element to array
arr.push (new content)
Method adds one or more elements to the end of an array and returns the new length of the array
Syntax: arr.push(element 1, element 2, ..., element n)
key memory
arr.unshift (new content)
Method adds one or more elements to the beginning of the array and returns the new length of the array
Syntax: arr.unshift(element 1, element 2, ..., element n)
Delete data from array
arr.pop()
Method removes the last element from the array and returns the element value
Syntax: arr.pop()
arr.shift()
arr.splice (subscript of operation, number of deletions)
Method to delete the specified element
arr.splice(start,deleteCount)
start starting position: Specify the starting position of modification (starting from 0)
deleteCount
Remove number of array elements
Optional (if omitted, it will be deleted from the specified position to the end by default)
arr.splice (starting position, delete several elements)
Array sort
Array.sort() method for sorting
Syntax: let arr = [4,2,1,5,3] arr.sort(function(a,b){ returna-b })