Answers for "how to access last index of array js"

34

javascript last index

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

js get last element of array

const array = ["foo", "bar", "fizz", "buzz"];
const lastElem = array.at(-1); // returns "buzz"
Posted by: Guest on March-17-2022

Code answers related to "how to access last index of array js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language