Get the last item in an array (JavaScript) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Get the last item in an array (JavaScript)

1st using length method: let arr = [22, 44, 66, 60, 7]; let le = arry[arr.length - 1]; console.log(le); // output: 7 ======= 2nd using slice() method: let arr = [22, 44, 66, 60, 7]; let le= arr.slice(-1); // output: 7 ======= 3rd using pop() method: let arr = [22, 44, 66, 60, 7]; let le= arr.pop(); // output: 7 which one fast? pop() method

3rd Sep 2022, 9:06 AM
Xavon Sakib
Xavon Sakib - avatar
1 Answer
+ 2
And your question is?
3rd Sep 2022, 9:14 AM
A͢J
A͢J - avatar