当前位置:网站首页>JS里的数组
JS里的数组
2022-06-23 14:24:00 【刘家奕_】
目录
数组(Array)
-数组也是一个对象
-它和我们普通对象功能类似,也是用来存储一些值的-不同的是普通对象是使用字符串作为属性名的,
而数组时使用数字来作为索引操作元素
-索引:
从0开始的整数就是索引
-数组的存储性能比普通对象要好,在开发中我们经常使用数组来存储一些数据
(1)读取数组中的元素
语法:数组[索引]
如果读取不存在的索引,他不会报错而是返回undefined
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
var sz = new Array();
sz[0] = 1;
sz[1] = 2;
sz[2] = 3;
alert(sz[1]);
</script>
</body>
</html>

(2)获取数组的长度
可以使用length属性来获取数组的长度(元素的个数)语法。数组.length
对于连续的数组,使用length可以获取到数组的长度(元素的个数)
对于非连续的数组,使用length会获取到数组的最大的索引+1
尽量不要创建非连续的数组
(3)修改length
如果修改的length大于原长度,则多出部分会空出来
如果修改的length小于原长度,则多出的元素会被删除
边栏推荐
- Selenium Edge的IE模式
- TS encapsulation request
- 【深入理解TcaplusDB技術】TcaplusDB構造數據
- 2021-05-08
- [in depth understanding of tcapulusdb technology] tcapulusdb business data backup
- Raspberry PI installing the wiring pi
- Illustration of ONEFLOW's learning rate adjustment strategy
- Babbitt | metauniverse daily must read: meta, Microsoft and other technology giants set up the metauniverse Standards Forum. Huawei and Alibaba joined. NVIDIA executives said that they welcomed partic
- 建议自查!MySQL驱动Bug引发的事务不回滚问题,也许你正面临该风险!
- Sectigo(Comodo)证书的由来
猜你喜欢

狂奔的极兔,摔了一跤
![[in depth understanding of tcapulusdb technology] tcapulusdb construction data](/img/0c/33d9387cd7733a0c6706a73f9535f7.png)
[in depth understanding of tcapulusdb technology] tcapulusdb construction data

山东:美食“隐藏款”,消费“扫地僧”

5分钟快速上线Web应用和API(Vercel)

JSR303数据校验

Self inspection is recommended! The transaction caused by MySQL driver bug is not rolled back. Maybe you are facing this risk!

图解OneFlow的学习率调整策略

Why is Xiaomi stuck in the chip quagmire?

Simple tutorial of live streaming with OBS

Uniswap acquires genie, an NFT transaction aggregator. Will the NFT transaction market change?
随机推荐
go语言的变量声明
2021-05-08
Selenium Edge的IE模式
NFNet:NF-ResNet的延伸,不用BN的4096超大batch size训练 | 21年论文
力扣解法匯總513-找樹左下角的值
等保备案是什么意思?应该去哪里办理备案?
Sectigo(Comodo)证书的由来
【二级等保】过二级等保用哪个堡垒机品牌好?
图解OneFlow的学习率调整策略
操作系统底层知识总结(面试)
MySQL高级语句一
Summary of operating system underlying knowledge (interview)
How to make food nutrition label
php 二维数组插入
谷歌&HuggingFace| 零样本能力最强的语言模型结构
Force deduction solution summary 513- find the value of the lower left corner of the tree
How to ensure long-term stable operation of EDI system
In this year's English college entrance examination, CMU delivered 134 high scores with reconstruction pre training, significantly surpassing gpt3
【深入理解TcaplusDB技術】TcaplusDB構造數據
快速排序的简单理解