I am currently designing a select dropdown input element for a webpage and I want to create a specific 'popular' options group that will be displayed at the top of the dropdown menu.
The data structure I am working with is as follows. I am trying to figure out a way to rearrange the items within the people array based on their names.
For instance, I need to reposition the following items:
pogo-stick from toys[2] -> toys[0]
cards from toys[3] to toys[2]
I have a list of popular toys, which includes:
popularToys: [
"cards", "pogo-stick"
]
My question is, how can I loop through the array of objects and organize them according to the new order specified?
Sample Data:
{
"toys": [
{
"name": "car",
"price": "10"
},
{
"name": "duck",
"price": "25"
},
{
"name": "pogo-stick",
"price": "60"
},
{
"name": "cards",
"price": "5"
}
]
}