Answers for "how to access second last index in array javascript"

34

last index array javascript

var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
Posted by: Guest on July-25-2019
1

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
Posted by: Guest on September-14-2020

Code answers related to "how to access second last index in array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language