当前位置:网站首页>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"]边栏推荐
- PAT 1157:校庆
- 基金的募集,交易与登记
- ZUCC_编译语言原理与编译_实验03 编译器入门
- 问题4 — DatePicker日期选择器,2个日期选择器(开始、结束日期)的禁用
- Promise的使用場景
- New technology practice, encapsulating the permission application library step by step with the activity results API
- Paper notes: multi label learning dm2l
- Fundamentals of 3D mathematics [17] inverse square theorem
- 487. 最大连续1的个数 II ●●
- io模型初探
猜你喜欢

JUC personal simple notes

PAT 1157:校庆

A preliminary study of IO model

【关于运维和网工的差别,一文说透】

2021-03-11 comp9021 class 8 notes

ZUCC_ Principles of compiling language and compilation_ Experiment 08 parsing LR parsing

ZUCC_ Principles of compiling language and compilation_ Experiment 03 getting started with compiler
![Fundamentals of 3D mathematics [17] inverse square theorem](/img/59/bef931d96883288766fc94e38e0ace.png)
Fundamentals of 3D mathematics [17] inverse square theorem

一文带你了解Windows操作系统安全,保护自己的电脑不受侵害

longhorn安装与使用
随机推荐
jwt(json web token)
ZUCC_编译语言原理与编译_实验05 正则表达式、有限自动机、词法分析
Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)
How to replace the web player easyplayerproactivex Key in OCX?
etcd备份恢复原理详解及踩坑实录
11--无重复字符的最长子串
Blue Bridge Cup_ Queen n problem
12--合并两个有序链表
All you know is the test pyramid?
Pat 1157: school anniversary
【无标题】
PAT 1157:校庆
MAYA重新拓布
[xinliu-s6 new model +sa 3-star Xinghai] the new two-way server of the third generation chip was launched and the product was updated~
2021-06-24: find the length of the longest non repeating character substring in a string.
【微服务~Nacos】Nacos服务提供者和服务消费者
Five level classification of loans
Robot acceleration level task priority inverse kinematics
Several ways you can't move zero (sequel)
OpenCV to realize the basic transformation of image