I have one array and other array for sort order. Now i want to sort the array according to the sort array items.
var checkedIds =["2","1","4"];//sort order array
//other array
var data1= {
"ProductImages": [
{ "checkBoxField": false, "itemId": 1, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 2, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 3, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 4, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 5, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 6, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 7, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 8,"rateValue":"$34" }
]
};
Output Should be
var data1= {
"ProductImages": [
{ "checkBoxField": true, "itemId": 2, "rateValue":"$34" },
{ "checkBoxField": true, "itemId": 1, "rateValue":"$34" },
{ "checkBoxField": true, "itemId": 4, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 3, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 5, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 6, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 7, "rateValue":"$34" },
{ "checkBoxField": false, "itemId": 8,"rateValue":"$34" }
]
};
checkedIds?checkedIdsarray?ProductImagesan object instead and make theitemIdthe key? You can usecheckedIdsto reference the keys when you need them."checkBoxField": true,as well?