JSFiddle - React, Tailwind, and code Playground
by Brewal Renault
JavaScript
var my_list = ["XXXS", "XXS", "XS", "S", "M", "L", "XL", "XXL", "XXXL"];
my_json = [
{
size: "L",
color: "black"
}, {
size: "M",
color: "blue"
}, {
size: "XXL",
color: "red"
}, {
size: "XXS",
color: "red"
}
];
var ordered_list = [];
for (i = 0; i < my_list.length; i++) {
for (j = 0; j < my_json.length; j++) {
if (my_list[i] == my_json[j].size) {
ordered_list.push(my_json[j]);
}
}
}
$("body").append(JSON.stringify(ordered_list));