Answers for "get the last element of a js lisit"

76

javascript get last element of array

var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
Posted by: Guest on February-19-2020
0

javascript last in a list

let list = ["item1", "item2", "item3", "etc"];
let last = list.reverse()[0]
// or
let last = list[list.length - 1]
// or
let last = list.slice(-1)
Posted by: Guest on February-20-2021

Code answers related to "get the last element of a js lisit"

Code answers related to "Javascript"

Browse Popular Code Answers by Language