getting array last element fetching

Solutions on MaxInterview for getting array last element fetching by the best coders in the world

showing results for - "getting array last element fetching"
Paula
13 Feb 2017
1let arry = [2, 4, 6, 8, 10, 12, 14, 16];
2console.time('array length property');
3let lastElement = arry[arry.length - 1];
4console.log(lastElement);
5console.timeEnd('array length property');
6
7console.time('array slice method');
8let lastElement1 = arry.slice(-1);
9console.log(lastElement1);
10console.timeEnd('array slice method');
11
12console.time('array pop method');
13let lastElement2 = arry.pop();
14console.log(lastElement2);
15console.timeEnd('array pop method');
16
17//Output:
18
19//16
20//array length property: 13.798ms
21//[ 16 ]
22//array slice method: 8.839ms
23//16
24//array pop method: 0.138ms
25