Answers for "get last element of object js"

2

las element of object

var fruitObject = { 'a' : 'apple', 'b' : 'banana', 'c' : 'carrot' };
Object.keys(fruitObject); // this returns all properties in an array ["a", "b", "c"]
fruitObject[Object.keys(fruitObject)[Object.keys(fruitObject).length - 1]] // "carrot"
Posted by: Guest on November-22-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
0

javascript how to get last property of object

fruitObject[Object.keys(fruitObject)[Object.keys(fruitObject).length - 1]] // "carrot"
Posted by: Guest on August-06-2021

Code answers related to "get last element of object js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language