[Vuejs]-How to get the object with the first next date from an array in Nuxt.js / Vue.js?

0👍

You need to bring your array into an order which relies on the sequence of the dates. You can do this with a custom sort function. Then, you can just increase the index by one and access the next element in the array.

Here is an example of how to sort the array by date.

const array = [{
  date: new Date(),
  value: 123
}, {
  date: new Date(),
  value: 321
}, {
  date: new Date(),
  value: 'test'
}];

console.log(array.sort((a, b) => {
  return a.date - b.date;
}));

See also this StackOverflow answer.

Leave a comment