Get the last element of an object

Let's assume that you have the following object:

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

javascript
let 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.