Let's assume that you have the following object:
javascriptlet authors = { author_1: 'Jeff', author_2: 'Elon', author_3: 'Bill', author_4: 'Erik' }
If you want to get the last element, you can use the pop()
function combined with Object.entries()
:
javascriptlet lastElement = Object.entries(authors).pop(); console.log(lastElement); //["author_4", "Erik"]
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.