[Vuejs]-How to save a list with dicts in cookies in JS?

1👍

Sorting can be done like this:

data.sort((a, b) => a.id - b.id);

0👍

Array.prototype.sort is your friend here. Your Array will be mutated this helper method so you may want to copy it first.

let data = [], ids = [5,6,4,0,9,1]
for (let i = 0; i < ids.length; i++) {
  data.push({id: ids[i], title: ''})
}
const sorted = data.slice(0).sort((a,b)=>a.id - b.id)

Leave a comment