当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
【kali-权限提升】(4.2.7)社会工程学工具包:权限维持创建后门、清除痕迹
真香|持一建证书央企可破格录取
matlab neural network ANN classification
Ankerui supports Ethernet communication, profibus communication embedded energy meter APM guiding technical requirements-Susie Week
奥特曼卡牌隐藏的百亿市场
小满nestjs(第四章 前置知识装饰器-实现一个GET请求)
获取数组最后一项别再用array.length-1了
力扣383-赎金信——哈希映射数组法
Cholesterol-PEG-Thiol,CLS-PEG-SH,胆固醇-聚乙二醇-巯基用于改善溶解度
Can I make a TCP connection without accept?
Toronto Research Chemicals盐酸乙环胺应用说明
Week 8 Deep learning for object detection
mysql duplicate data group multiple latest records
Haven't tried line art videos this year??
访问控制知识
明明加了唯一索引,为什么还是产生重复数据?
2.3 监督学习-2
数据集成API如何成为企业数字化转型的关键?
Overview of Security Analysis Technology for Smart Home Devices
Two methods of implementing inverted strings in C language








