Answers for "how to determine if item is last in array js"

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 check the last item in an array javascript

const colors = ['red', 'yellow', 'green', 'blue']
const lastItem = colors[colors.length - 1]
console.log(lastItem)
Posted by: Guest on February-01-2021

Code answers related to "how to determine if item is last in array js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language