当前位置:网站首页>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 ); // 3Negative numbers start from -1 to represent the last digit.
边栏推荐
猜你喜欢

visual studio 2022调试技巧介绍

听音识情绪 | 程序员手把手教你搭建神经网络,更快get女朋友情绪,求生欲max!

DP-Differential Privacy概念介绍

基于SSM实现手机销售商城系统

阿里二面:没有 accept,能建立 TCP 连接吗?

看完这波 Android 面试题;助你斩获心中 offer

What to do if Windows 11 can't find Internet Explorer

hdu 2094 产生冠军(STL map || 拓扑 || STL set)

加工制造业智慧采购系统解决方案:助力企业实现全流程采购一体化协同

如何从800万数据中快速捞出自己想要的数据?
随机推荐
企业数据打通有什么好处?不同行业怎么解决数据打通难题?
IS31FL3737B general 12 x 12 LED drive 40 QFN I2C 42 ma
智能家居设备安全分析技术综述
安装多版本php(php5.6,php7.2)
软件测试技术之如何编写测试用例(6)
【高效工具】远程控制软件 ToDesk(收藏夹)
移动端,PC端,微信等常用平台和浏览器判断
Two methods of implementing inverted strings in C language
【二叉树】树的子结构
下秒数据:湖仓一体带来的现代数据堆栈变革开始了
【NOI模拟赛】防AK题(生成函数,单位根,Pollard-Rho)
阿里二面:没有 accept,能建立 TCP 连接吗?
DP-Differential Privacy概念介绍
嵌入式开发:使用FILL提高代码完整性
Can I make a TCP connection without accept?
力扣15-三数之和——HashSet&双指针法
Cholesterol-PEG-Thiol,CLS-PEG-SH,胆固醇-聚乙二醇-巯基用于改善溶解度
Week 8 Deep learning for object detection
明明加了唯一索引,为什么还是产生重复数据?
面试官:Redis 大 key 要如何处理?