Is there a way to sort an array of objects using a primary and secondary value? What i mean is an array like this:
[
{ primary: 0, secondary: 'a' },
{ primary: 1, secondary: 'a' },
{ primary: 1, secondary: 'b' },
{ primary: 0, secondary: 'b' }
]
will be sorted using the primary value, so the first two objects with the primary value of 0 come first then the values of 1 come second, and then it will be again sorted by the secondary value and it will result in the array becoming
[
{ primary: 0, secondary: 'a' },
{ primary: 0, secondary: 'b' },
{ primary: 1, secondary: 'a' },
{ primary: 1, secondary: 'b' }
]
im havent really touched the Array.sort()
before so im trying to find out how to do this, any help will be appreciated!