当前位置:网站首页>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小于原长度,则多出的元素会被删除
边栏推荐
- Résumé de la méthode de déduction de la force 513 - trouver la valeur du coin inférieur gauche de l'arbre
- HCIA 网络基础
- AXI_ Round_ Robin_ Arbiter design - aw and W channels
- 从3开始,在业务系统中增加分页功能
- 【opencv450】椒盐噪声demo
- The largest IPO of Hong Kong stocks this year, with a net worth of 66billion, is the "King" sitting on the mine
- 2021-05-08
- 2021-06-07
- ts封装请求
- Golang -- multiple processing scenarios for files
猜你喜欢

How to solve the problem that iterative semi supervised training is difficult to implement in ASR training? RTC dev Meetup

【二级等保】过二级等保用哪个堡垒机品牌好?

图解OneFlow的学习率调整策略

The well-known face search engine provokes public anger: just one photo will strip you of your pants in a few seconds

In this year's English college entrance examination, CMU delivered 134 high scores with reconstruction pre training, significantly surpassing gpt3

WebService接口发布和调用

如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup

The first public available pytorch version alphafold2 is reproduced, and Columbia University is open source openfold, with more than 1000 stars

巴比特 | 元宇宙每日必读:Meta、微软等科技巨头成立元宇宙标准论坛组织,华为、阿里加入,英伟达高管称欢迎来自加密世界的参与者...

The new version of Alibaba Seata finally solves the idempotence, suspension and empty rollback problems of the TCC mode
随机推荐
How to make food nutrition label
2021-04-15
MySQL create and manage tables
2021-04-15
Error creating bean with name xxx Factory method ‘sqlSessionFactory‘ threw exception; nested excepti
Converging ecology, enabling safe operation, Huawei cloud security, cloud brain intelligent service security
力扣解法匯總513-找樹左下角的值
How to use note taking software flowus and note for interval repetition? Based on formula template
php 二维数组插入
《墨者学院——SQL手工注入漏洞测试(MySQL数据库)》
AXI_ Round_ Robin_ Arbiter design - aw and W channels
HCIA 网络基础
What do you mean by waiting for insurance records? Where should I go for filing?
中国矿大团队,开发集成多尺度深度学习模型,用于 RNA 甲基化位点预测
图解OneFlow的学习率调整策略
Xampp中mysql无法启动问题的解决方法
这届文娱人,将副业做成了主业
山东:美食“隐藏款”,消费“扫地僧”
[datahub] LinkedIn datahub learning notes
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