array last second last 3 last add in new array javascript code example
Example 1: find last element in array javascript
const numArray = [1,2,3,4,5];
const lastNumber = numArray.reverse()[0];
Example 2: javascript get second last element in array
const myNumbers = [100, 200, 300, 400, 500];
// option one
const seconLastNumber = myNumbers.slice(-2, -1)[0]) // 400
// option two
const seconLastNumber = myNumbers[numbers.length - 2]; // 400