当前位置:网站首页>Don't use array.length-1 to get the last item of the array
Don't use array.length-1 to get the last item of the array
2022-08-09 22:07:00 【Maple moving forward】
Please don't use array.length-1 to get the last item of the array. There is a more convenient and concise method: at , which is a method on the array prototype.
mdn:
Theat()
method takes an integer value and returns the item at that index, positive and negative numbers are allowed.Negative integers count down from the last item in the array.
eg:
const a = [1,2,3];const lastItem = a.at(-1);console.log(lastItem ); // 3
Negative numbers start from -1 to represent the last digit.
边栏推荐
猜你喜欢
随机推荐
Toronto Research Chemicals加米霉素-d4说明书
Openharmony Lightweight System Experiment--GPIO Lighting
基于模糊PID控制器的水温控制系统仿真
DSPE-PEG-Azide,DSPE-PEG-N3,磷脂-聚乙二醇-叠氮可和DBCO直接反应
Redis 大的情况下,key 要如何处理?
leetcode 二叉树的分层遍历1
C语言之实现倒置字符串的两种方法
OpenSSL SSL_read: Connection was reset, errno 10054
Laravel之队列「建议收藏」
【Jmeter】分布式搭建
没有 accept,我可以建立 TCP 连接吗?
小满nestjs(第四章 前置知识装饰器-实现一个GET请求)
Win11搜索不到文件的解决方法
LeetCode每日一题(321. Create Maximum Number)
Next second data: the transformation of the modern data stack brought about by the integration of lake and warehouse has begun
buuctf(探险2)
获取一段程序运行的时间
3D感知(二):单目3D物体检测
An overall security understanding and method of cyberspace based on connection and security entropy
安科瑞支持以太网通讯、profibus通讯嵌入式电能表APM指导性技术要求-Susie 周