Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
 
PREVIOUS NEXT
Tagged: #javascript #element #array
ADD COMMENT
Topic
Name
5+3 =