What am trying to do is to order the above items with the length of variant such that after the order the second item will be first since it has 3 items in the variant array
I have the following data structure and code:
var items = [
{name: 'one', variant: [{id: 1, name: 'ABS'}, ]},
{name: 'second', variant: [{id: 1, name: 'BTC'}, {id: 2, name: 'SAM'}, {id: 2, name: 'KXD'}]}
]
console.log(items.sort((a, b) => a.variant.length > b.variant.length))
But this does not sort the items. What am i missing as i would like to do this in ES6