I am stuck when looks at this solution whch talks about how to sorting object property by values
const maxSpeed = {
car: 300,
bike: 60,
motorbike: 200,
airplane: 1000,
helicopter: 400,
rocket: 8 * 60 * 60
};
console.log( Object.entries(maxSpeed))
const sortable = Object.fromEntries(
Object.entries(maxSpeed).sort(([,a],[,b]) => {
console.log(a,b)
return a-b
})
);
console.log(sortable);
Why using a Trailing commas there, why it makes it returns [1]
item in the nested array (e.g. [car,300 ][0])?
By looking at mdn descrption about the trailing comma, I still don't have any ideas:
Trailing commas (sometimes called "final commas") can be useful when adding new elements, parameters, or properties to JavaScript code. If you want to add a new property, you can add a new line without modifying the previously last line if that line already uses a trailing comma. This makes version-control diffs cleaner and editing code might be less troublesome.
Any hints and comments will be appreciated.