In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use Javascrip's for loop and array". In daily operation, I believe many people have doubts about how to use Javascrip's for loop and array. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "Javascrip for loop and array how to use". Next, please follow the editor to study!
Loop-basic use of forfor loop
For loop syntax: repeat code execution
Benefits: write the declaration starting value, loop condition, and change value together to make it clear at a glance
For (variable start value; loop condition; variable update) {loop body}
The difference between a for loop and a while loop:
For loops are recommended when the number of loops is specified.
It is recommended to use while loop when the number of loops is not clear.
Exit the loop
End of loop:
Continue: end this cycle and continue the next cycle
Break: jump out of the cycle
Loop nesting
One loop after another, usually used in a for loop
For (variable start value; Loop condition; variable Update) {for (variable start value; Loop condition; variable Update) {Loop body}} what is the array array?
Array is a type of data that can be stored sequentially.
Basic use of arrays
Declaration syntax
Let array name = [data 1, data 2,..., data n]
1 arrays are saved sequentially, so each data has its own number
two。 The number in the computer 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. Fetch data by subscript
two。 What type is taken out? access it according to the characteristics of this type.
Some terms
Element: each data saved in an array is called an array element
Subscript: the number of the data in the array
Length: the number of data in an array, obtained through the length attribute of the array
Array name .length traversal array
Every element in the array is accessed with a loop, which is usually traversed with a for loop
For (let I = 0; I < array name.length; iArray +) {array name [I]} Operand array
Array is essentially a collection of data, and manipulating data is nothing more than adding, deleting, changing and querying syntax.
1. Query array data, or what we call access array data array [subscript]
two。 Change: reassign array [subscript] = new value
3. Add: add new data to the array
Arr.push (what's new)
Arr.unshift (what's new)
4. Deleting: deleting data in an array
Arr.pop ()
Arr.shift ()
Arr.splice (subscript of operation, number of deletions)
Add new data to the array
The array .push () method adds one or more elements to the end of the array and returns the new length of the array (emphasis).
Arr.push (element 1, element 2,..., element n)
The arr.unshift method adds one or more elements to the beginning of the array and returns the new length of the array
Arr.unshift (element 1, element 2,..., element n)
Array delete element
Array. The pop () method removes the last element from the array and returns the value of that element
Arr.pop ()
Array. The shift () method removes the first element from the array and returns the value of that element
Arr.shift ()
Array. The splice () method deletes the specified element (emphasis)
Arr.splice (start, deleteCount) arr.splice (start position, delete several elements)
Start start position:
Specify the start position of the modification (count from 0) deleteCount:
Represents the number of array elements to remove
Optional. If omitted, it is deleted from the specified starting position to the end by default
Delete the usage scene of the element:
If the lottery is drawn randomly, the winning user needs to be deleted from the array, and repeated lucky draw is not allowed.
Click the delete button, and the relevant data will be deleted from the product data.
At this point, the study on "Javascrip's for loop and how to use arrays" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.