Get the last element of an object

Let's assume that you have the following object:

let 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():

let lastElement = Object.entries(authors).pop(); 

//["author_4", "Erik"]

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.