I have an object with keys and data. From a key I want to get the previous item.
I've seen similar topics before but the solutions are really complicated.
I also added a function that does not work but how I wish it would work
Simplified code
let obj = {
slug: 'my-page',
title: 'My title',
description: 'My description',
content: 'My content'
};
let previous = obj.previousItem('description'); // Does not work
console.log(previous);
Expected result
{ title: 'My title' }
- ES5 or even ES6 is fine
- I prefer a simple solution to a complicated one, maybe without loops