当前位置:网站首页>JS中的数组
JS中的数组
2022-07-25 10:54:00 【c_perfectworld】
数组
指一组数据的集合,每个数据称为元素,数组中可以存放任意类型的元素,数组是一种将一组数据存储在单个变量名下的优雅方式
数组的创建方式
- 利用new创建数组
- 利用数组字面量创建数组
var 数组名 = new Array()A要大写
利用数组字面量创建数组
- 数组的字面量是【】
- 声明数组并赋值是数组的初始化
获取数组元素
数组的索引:
用来访问数组元素的序号(从0开始)
数组名[索引号]
遍历数组
因为数组索引号从0开始,所以i必须从0开始
输出的时候写 arr[i] i 计数器当索引号来用
数组长度
arr.length
数组中新增元素
可以通过修改length长度以及索引号增加数组元素
- 通过修改length长度实现数组扩容的目的
- length属性是可读写的
通过修改数组索引新增数组元素
- 可以通过修改数组索引的方式追加数组元素
- 不能直接给数组名赋值,否则会覆盖之前的数据
边栏推荐
- 将字符串转换为数字
- 菜单栏+状态栏+工具栏==PYQT5
- 任何时间,任何地点,超级侦探,认真办案!
- Leetcode sword finger offer 27. image of binary tree
- SQL注入 Less23(过滤注释符)
- [tree] 100. Same tree
- 教你如何通过MCU配置S2E为TCP Server的工作模式
- 如何判断静态代码质量分析工具的性能?这五大因素必须考虑
- Dynamic planning question 05_ Missile interception
- Let sports happen naturally, and fire creates a new lifestyle
猜你喜欢

黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。
Definition of information entropy

OneNET平台控制W5500开发板LED灯

Talking about Devops monitoring, how does the team choose monitoring tools?

活动报名 | 玩转 Kubernetes 容器服务提高班正式开营!

论文解读(MaskGAE)《MaskGAE: Masked Graph Modeling Meets Graph Autoencoders》

SQL注入 Less23(过滤注释符)

Teach you how to configure S2E as the working mode of TCP server through MCU

WIZnet W5500系列培训活动之“MQTT协议讲解和实践(接入OneNET)”

JDBC summary
随机推荐
cookie and session
Job interviews are always a second kill? After reading the seckill system notes secretly stored by JD T8, I have given my knees
Attendance system based on w5500
Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.
小微企业智能名片管理小程序
软件缺陷的管理
ESP8266 使用 DRV8833驱动板驱动N20电机
Leetcode sword finger offer 27. image of binary tree
[recursion] 938. Range and of binary search tree
论文解读(MaskGAE)《MaskGAE: Masked Graph Modeling Meets Graph Autoencoders》
Information management system for typical works of urban sculpture (picture sharing system SSM)
Shell fourth day homework
W5500 multi node connection
SQL language (I)
Talking about Devops monitoring, how does the team choose monitoring tools?
Summary of combination problems of Li Kou brush questions (backtracking)
贪心问题01_活动安排代码分析
Details of the list of state products that Apple announced to be eligible for the sales tax holiday in the United States
擎创科技加入龙蜥社区,共建智能运维平台新生态
Use three.js to realize the cool cyberpunk style 3D digital earth large screen