📅  最后修改于: 2022-03-11 15:01:36.590000             🧑  作者: Mango
// how to find last element in array in javascript
// 1. Array.prototype.length
const arr = [1,2,3,4,5];
console.log(arr[arr.length - 1]);
// Result: 5
// 2. Array.prototype.slice()
const last = arr.slice(-1);
console.log(+last);
// Result: 5