Seeking advice on sorting array objects in JavaScript based on input sequence.
Given an array input [abc, xyz, 123], the output array object looks like:
[
{
"label" : "positive",
"id" : "abc"
},
{
"label" : "positive",
"id" : "xyz"
},
{
"label" : "negative",
"id" : "abc"
},
{
"label" : "positive and negative",
"id" : "abc"
},
{
"label" : "neg",
"id" : "123"
},
{
"label" : "positive",
"id" : "xyz"
}
]
The desired output should arrange objects based on input sequence:
abc is the first element, xyz is the second element, and 123 is the third element.
Therefore, the output should display all "abc" objects first, followed by "xyz" objects, and finally "123" objects.
[
{
"label" : "positive",
"id" : "abc"
},
{
"label" : "negative",
"id" : "abc"
},
{
"label" : "positive and negative",
"id" : "abc"
},
{
"label" : "positive",
"id" : "xyz"
},
{
"label" : "positive",
"id" : "xyz"
},
{
"label" : "neg",
"id" : "123"
}
]
If you have any suggestions on how to achieve this sorting, please share them. Thank you!