I have an object like this:
var obj = [
{ name: "name1", type: 4 },
{ name: "name6", type: 2 },
{ name: "name2", type: 5 },
{ name: "name3", type: 1 },
{ name: "name5", type: 2 },
{ name: "name4", type: 3 }
]
I want to return a sorted array, so that at the top of the array there are objects with type 2 or 3, sorted further by the name field:
var obj = [
{ name: "name4", type: 3 }
{ name: "name5", type: 2 },
{ name: "name6", type: 2 },
{ name: "name1", type: 4 },
{ name: "name2", type: 5 },
{ name: "name3", type: 1 }
]
How can I implement this?
p.s. I would also like to see a variant if type is enum (e.g.,
export enum Types {
Type0 = 0,
Type1 = 1,
.....}
)