当前位置:网站首页>Array method of J S, loop
Array method of J S, loop
2022-07-28 09:52:00 【Laikang Erguotou】
One , function
1. Defined function
function Function name ( Parameters 1, Parameters 2,… ) {
//JavaScript sentence ;
[return Return value ]
}
2. Call function Event name =" Function name ( )" ;
3. Scope of variable (1) Global variables (2) local variable
var i=20;
function first(){
var i=5;
document.write("<br/> function first Medium i The value is :"+i);
}
function second(){
var t=document.getElementById("number").value;
if(t>i){
document.write(" function second Medium t The value is :"+t);}
else{
document.write(" In a global variable i The value is :"+i);
}
first();
}
Two , Array ( A collection of one or more values with the same data type )
Create array
var Array name = new Array(size);
new: Keywords representing arrays
size: Indicates that... Can be stored in the array Total number of elements put
***JavaScript The array in stores a series of values with a name , Use subscripts to distinguish each value in the array , Array subscript from 0 Start ***
Array assignment
On declaration, assign
var week= new Array (" Sunday "," Monday "……);
Assign values respectively
var week= new Array ( 7);
week[0] = " Sunday ";
week[1] = " Monday ";
week[2] = " Tuesday ";
week[3] = " Wednesday ";
……
Accessing array elements
Directly access the elements of the array through the name and subscript of the array
Array common methods and properties
| Category | name | explain |
| attribute | length | Sets or returns the number of elements in an array |
| Method | join() | Put all the elements of the array into a string , Separated by a separator |
| sort() | Sort the array | |
| push() | Add one or more... To the end of the array Elements , And returns the new length |
js Array syntax
push() Add an element to the end of the array
pop() Delete array end element
unshift() Add elements to the array header
shift() Delete the array header element
splice() Delete the elements in the array ( The first parameter is the starting index , The second is the number of deletions )
3、 ... and , loop
What is cycle ?
A cycle is when conditions are met , To perform an operation repeatedly
The advantages of recycling
1. Resolve duplicate actions
2. Reduce the amount of code written , Make the code structure clear
3. Improve the readability of the code
The structure of the cycle
1. The loop condition
2. Cyclic operation
Classification of cycles
1.for Loop structure
2.while Loop structure
// 1、for loop Subscript / key / key 【 Known condition , Known range ( First judge , After execution )】
/* for(let i = 0; i < arr.length;i++){
document.write(arr[i]+"<br/>");
}
*/
// 2、 while() loop Subscript / key / key 【 Unknown condition , Unknown range ( First judge , After execution )】
/* let i = 0;
while(i < arr.length){
document.write(arr[i]+"<br/>");
i++;
} */
//3、do while() loop Subscript / key / key 【 At least once ( Execute first , Post judgment )】
/* let i = 0;
do{
// Loop code block
document.write(arr[i]+"<br/>");
i++;
}
while(i < arr.length); */
// 4、for of loop ES5 value / value / Elements 【 Loop through groups 】
/* for(let value of arr){
document.write(value+"<br/>");
} */
// 5、 for in loop ES6 Subscript / key / key
/* for(let i in arr){
document.write(arr[i]+"<br/>");
} */
// 6、 forEach() Array methods Anonymous callback function Thank you for your support !
Remember to support Erguotou , One button three times !
边栏推荐
- Buckle 376 swing sequence greedy
- (iros 2022) monocular visual inertial odometer based on event camera
- go语言切片Slice和数组Array对比panic runtime error index out of range问题解决
- include 与 require include_once 与 require_once 的区别
- OSS直连上传-Rails服务实践
- 《我的Vivado实战—单周期CPU指令分析》
- 关于CLR GC调优的一些问题
- PHP连接mysql原生代码
- 常用工具函数 持续更新
- View的工作原理
猜你喜欢

设计一个支持百万用户的系统

mq的学习

极致通缩和永动机模型,将推动 PlatoFarm 爆发

使用Xposed对软件进行破解

MySQL master-slave architecture. After the master database is suspended and restarted, how can the slave database automatically connect to the master database

老板:公司系统太多,能不能实现账号互通?

Opencv installation configuration test

C# 读写文件从用户态切到内核态,到底是个什么流程?

With such a simple verification, 80% of programmers can't do it, let alone understand it!

This wechat plug-in is very easy to use
随机推荐
With such a simple verification, 80% of programmers can't do it, let alone understand it!
初学C#必须要掌握的基础例题
go语言切片Slice和数组Array对比panic runtime error index out of range问题解决
NET 3行代码实现文字转语音功能
Shell implements the backup / recovery / migration functions of harbor v1/v2
View的工作原理
redis的基础知识
Machine learning (10) -- hypothesis testing and regression analysis
FixedWindowRollingPolicy简介说明
超级原始人系列盲盒即将上线,PlatoFarm赋能超多权益
TCP 基础知识
实验四 使用fdisk对硬盘进行管理
Analysis of the internal principle of LinkedList
C# 读写文件从用户态切到内核态,到底是个什么流程?
C form application uses object binding DataGridView data binding
Window源码解析(一):与DecorView的那些事
Window源码解析(三):Window的更新机制
今天和大家聊一聊mysql数据库的数据类型
3 minutes to tell you how to become a hacker | zero foundation to hacker getting started guide, you only need to master these five abilities
使用IdentityServer出现过SameSite Cookie这个问题吗?