sorted data list based on another custom order list array
This code get unsorted data list and return sorted list based on given order list array.
by Sunny SM
JavaScript
const devices = [
{
"brand":"Samsung XXXX",
"model":"Galaxy S20 Ultra",
"modelCode":"XSAMGLS20ULTRA",
"type":"OUTRIGHT",
"generationIdentifier":"",
"fromPrice":1999,
"monthlyFromPrice":83.29,
"imageUrl":""
},
{
"brand":"Samsung",
"model":"Galaxy Z Flip",
"modelCode":"XSAMGLFLIP",
"type":"OUTRIGHT",
"generationIdentifier":"4G",
"fromPrice":2199,
"monthlyFromPrice":91.62,
"imageUrl":""
},
{
"brand":"Samsung",
"model":"Galaxy A51",
"modelCode":"XSAMA51",
"type":"OUTRIGHT",
"generationIdentifier":"4G",
"fromPrice":599,
"monthlyFromPrice":20.79,
"imageUrl":""
},
{
"brand":"Apple",
"model":"iPhone 12 5G",
"modelCode":"XAPPIP125G",
"type":"OUTRIGHT",
"generationIdentifier":"5G",
"fromPrice":1599,
"monthlyFromPrice":56.21,
"imageUrl":""
},
{
"brand":"Apple",
"model":"iPhone SE (2nd Gen) 2020",
"modelCode":"XAPPIPSE2GN2020",
"type":"OUTRIGHT",
"generationIdentifier":"4G",
"fromPrice":759,
"monthlyFromPrice":31.54,
"imageUrl":""
},
{
"brand":"Apple",
"model":"iPhone 12 PRO 5G",
"modelCode":"XAPPIP12PRO5G",
"type":"OUTRIGHT",
"generationIdentifier":"5G",
"fromPrice":2219,
"monthlyFromPrice":70.79,
"imageUrl":""
},
{
"brand":"Apple",
"model":"iPhone XR",
"modelCode":"XAPPIPXR",
"type":"OUTRIGHT",
"generationIdentifier":"4G",
"fromPrice":1499,
"monthlyFromPrice":62.46,
"imageUrl":""
},
{
"brand":"Apple",
"model":"iPhone SE (2nd Gen)",
"modelCode":"XAPPIPSE2GN",
"type":"OUTRIGHT",
"generationIdentifier":"4G",
"fromPrice":749,
"monthlyFromPrice":31.21,
"imageUrl":""
},
{
"brand":"Apple",
"model":"IPHONE X",
"modelCode":"XAPPIPIPHONEX-ST",
"type":"OUTRIGHT",
"generationIdentifier":"4G",
"fromPrice":1488,
"monthlyFromPrice":62,
"imageUrl":""
},
{
...