I am looking for some help in relation to the next code:
var items = [
{ name: 'Edward', value: 21 },
{ name: 'Sharpe', value: 37 },
{ name: 'And', value: 45 },
{ name: 'The', value: -12 },
{ name: 'Magnetic', value: 37 },
{ name: 'Zeros', value: 37 }
];
// Sort by value
items.sort(function (a, b) {
return a.value - b.value;
});
So, after I sort the items
of the array in ascending or descending order, I want to extract the sub-array of objects that share the same value. Is there an easy approach for this in javascript
?
The output related to previous example should be like:
[
{ name: 'Magnetic', value: 37 },
{ name: 'Sharpe', value: 37 },
{ name: 'Zeros', value: 37 }
]