Answers for "how to target last value from array"

26

js take last item in array

const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
Posted by: Guest on March-16-2020
0

how to get the last element in an array

var colors = ["green", "blue", "red"]
var lastElem = colors.at(-1)
Posted by: Guest on September-06-2021

Code answers related to "how to target last value from array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language