当前位置:网站首页>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小于原长度,则多出的元素会被删除
边栏推荐
- 杀入美团、饿了么腹地,京东外卖劲儿有多大?
- 【云驻共创】智能供应链计划:提升供应链决策水平,帮助企业运营降本增效
- ASP. Net C pharmacy management information system (including thesis) graduation project [demonstration video]
- raspberry pi安装 wiringpi
- Golang-- judge whether the strings are equal
- 32. Compose 优美的触摸动画
- Uniswap acquires genie, an NFT transaction aggregator. Will the NFT transaction market change?
- After nine years at the helm, the founding CEO of Allen Institute retired with honor! He predicted that Chinese AI would lead the world
- 2021-05-08
- vim备份历史命令
猜你喜欢

SQL注入漏洞(原理篇)

2021-05-08

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

ICML 2022 𞓜 context integrated transformer based auction design neural network

港股今年最大IPO来了,660亿身家,坐在矿山上的“大王”

js遍历数组(用forEach()方法)

操作系统底层知识总结(面试)

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

k8s--部署单机版MySQL,并持久化

【opencv450】椒盐噪声demo
随机推荐
掌舵9年,艾伦研究所创始CEO光荣退休!他曾预言中国AI将领跑世界
2021-05-08
JSR303数据校验
ASP. Net C pharmacy management information system (including thesis) graduation project [demonstration video]
2021-04-15
Tencent ECS failed to send email
JSP_ SSM Wanfu cinema ticket sales management system, including paper [demonstration video]
2021-06-07
系统设计与分析-技术报告-定时清理验证码的一种解决方案
建议自查!MySQL驱动Bug引发的事务不回滚问题,也许你正面临该风险!
腾讯云服务器发送邮件失败
Error creating bean with name xxx Factory method ‘sqlSessionFactory‘ threw exception; nested excepti
力扣解法汇总513-找树左下角的值
ai智能机器人让我们工作省时省力
Raspberry PI installing the wiring pi
阿里 Seata 新版本终于解决了 TCC 模式的幂等、悬挂和空回滚问题
KDD'22「阿里」推荐系统中的通用序列表征学习
When I went to oppo for an interview, I got numb...
Mysql database - log management, backup and recovery
[deeply understand tcapulusdb technology] tcapulusdb import data