当前位置:网站首页>JS to get the last element of the array
JS to get the last element of the array
2022-06-24 08:33:00 【User 2323866】
Here is js Three ways to get the last element of an array
One 、JavaScript pop() Method
pop() Method is used to delete and return the last element of the array . Be careful :pop() Method will delete arrayObject Last element of , Reduce the length of the array by 1, And return the value of the element it deleted . If the array is already empty , be pop() Don't change the array , And back to undefined value .
var arr = new Array("js","JavaScript","jQuery");
var end = arr.pop()
console.log(end);//jQuery
console.log(arr);//["js", "JavaScript"]Two 、 Array of length attribute
var arr = new Array("js","JavaScript","jQuery");
var end = arr[arr.length-1]
console.log(end);//jQuery3、 ... and 、JavaScript slice() Method
slice() Method to return selected elements from an existing array . But the type of data returned is array No string Pay attention to this !
var arr = new Array("js","JavaScript","jQuery");
var end = arr.slice(-1);
console.log(end);//["jQuery"]边栏推荐
- JUC个人简单笔记
- SQL intra statement operation
- [introduction to point cloud dataset]
- 【关于运维和网工的差别,一文说透】
- Which is the first poem of Tang Dynasty?
- Easydss anonymous live channel data volume instability optimization scheme sharing
- ZUCC_ Principles of compiling language and compilation_ Experiment 02 fsharp Ocaml language
- 12--合并两个有序链表
- 12-- merge two ordered linked lists
- Question bank and simulation examination for operation certificate of refrigeration and air conditioning equipment in 2022
猜你喜欢

ZUCC_编译语言原理与编译_实验05 正则表达式、有限自动机、词法分析

ZUCC_编译语言原理与编译_实验04 语言与文法

Use of swift basic closure /block (source code)

权限模型 DAC ACL RBAC ABAC

ZUCC_编译语言原理与编译_实验08 语法分析 LR 分析

问题3 — messageBox弹框,修改默认背景色

Two methods of QT exporting PDF files

2021-03-04 comp9021 class 6 notes

About the iframe anchor, the anchor is offset up and down, and the anchor has page display problems Srcdoc problem of iframe

独立站运营中如何提升客户留存率?客户细分很重要!
随机推荐
2021-03-04 COMP9021第六节课笔记
【微服务~Nacos】Nacos服务提供者和服务消费者
Synthesize video through ffmpeg according to m3u8 file of video on the network
2021-03-04 comp9021 class 6 notes
How to implement approval function in Tekton
将mysql的数据库导出xxx.sql,将xxx.sql文件导入到服务器的mysql中。项目部署。
2022年流动式起重机司机特种作业证考试题库及在线模拟考试
PAT 1157:校庆
5 minutes, excellent customer service chat handling skills
[micro services ~nacos] Nacos service providers and service consumers
2021-03-11 comp9021 class 8 notes
Ordinary token
[real estate opening online house selection, WiFi coverage temporary network] 500 people are connected to WiFi at the same time
Scénarios d'utilisation de la promesse
Introduction to RCNN, fast RCNN and fast RCNN
11--无重复字符的最长子串
Promise的使用场景
Question 3 - MessageBox pop-up box, modify the default background color
贷款五级分类
11-- longest substring without repeated characters