当前位置:网站首页>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.
边栏推荐
猜你喜欢
新出现的去中心化科学能够为科学领域带来什么?
mysql duplicate data group multiple latest records
Definition and Basic Operations of Sequence Tables
企业数据打通有什么好处?不同行业怎么解决数据打通难题?
Application of Acrel5000web Energy Consumption System in a College-Susie Week
2.3 监督学习-2
线性表的定义和基本操作
leetcode 二叉树的公共近祖先
tki-tree 树组件控制默认展开第几层数据
Ali Ermi: Without accept, can a TCP connection be established?
随机推荐
时序攻击
Week 8 Deep learning for object detection
小满nestjs(第四章 前置知识装饰器-实现一个GET请求)
SqlServer 2016 安装相关问题
力扣15-三数之和——HashSet&双指针法
tki-tree 树组件控制默认展开第几层数据
Interviewer: How to deal with Redis big key?
AttributeError: module 'click' has no attribute 'get_os_args'
【kali-密码攻击】(5.1.1)密码在线破解:Hydra(图形界面)
基于网络数据流的未知密码协议逆向分析
没有 accept,我可以建立 TCP 连接吗?
Simulation of Water Temperature Control System Based on Fuzzy PID Controller
Definition and Basic Operations of Sequence Tables
Access control knowledge
新起之秀 DPU,正在掀起数据中心变革!
Application of Acrel5000web Energy Consumption System in a College-Susie Week
LeetCode每日一题(321. Create Maximum Number)
Toronto Research Chemicals加米霉素-d4说明书
看完这波 Android 面试题;助你斩获心中 offer
Acrel5000web能耗系统在某学院的应用-Susie 周