I have the json response which I want to make the order based on the label .Is it possible to arrange the json response data based on the stander fixed order.want to arrang in the order defined any required json let order={"data":["test1","test2","test3","test4","test5","test6","test7","test8"]}
(text may vary).Is it possible to arrange in order
let order={"data":["test1","test2","test3","test4","test5","test6","test7","test8"]}
const input = {
"data_report": [{
"data": [1, 2, 0, 3],
"label": "user2",
"backgroundColor": "blue"
},
{
"data": [3, 4, 2, 5],
"label": "test3",
"backgroundColor": "#a3eaae"
},
{
"data": [2, 3, 1, 4],
"label": "test4",
"backgroundColor": "#37bd11"
},
{
"data": [1, 2, 0, 3],
"label": "test7",
"backgroundColor": "#43bee3"
},
{
"data": [1, 2, 0, 3],
"label": "user5",
"backgroundColor": "#a3eaae"
},
{
"data": [0, 1, 0, 2],
"label": "test6",
"backgroundColor": "#1195bd"
},
{
"data": [0, 1, 0, 2],
"label": "test1",
"backgroundColor": "#aeb5b7"
},
{
"data": [1, 2, 0, 3],
"label": "test7",
"backgroundColor": "pink"
}
],
"weeks": ["Week 1 ", "Week 2 ", "Week 3 ", "Week 4 "]
}
var sorted = input.data_report.sort((item)=>{return order.data;});
console.log( sorted);
<div class="test"></div>