Answers for "find last object in array"

25

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
9

javascript last element of array

let arr = ['a', 'b', 'c']
arr.slice(-1)[0] // returns last element in an array
Posted by: Guest on May-18-2020
3

get last item in array

let array = [1,2,3,4,5]

let sliced = array.slice(-1)[0]

//OR

let popped = array.slice(-1).pop()

//OR

let lengthed = array[array.length - 1]
Posted by: Guest on August-14-2020
2

how to find the last object in an array

let array = [0,1,2,3,4,5,6,7,8,9]
let lastOfArray = array[array.length-1]
Posted by: Guest on September-05-2020

Code answers related to "find last object in array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language