- 16, May 2024
- #1
var originalObject = [{
"CatID": 15,
"Currently": "is One",
"ParentID": 16,
"Should": "should be One"
}, {
"CatID": 17,
"Currently": "is Two",
"ParentID": 16,
"Should": "should be Two"
}, {
"CatID": 18,
"Currently": "is Three",
"ParentID": 16,
"Should": "should be Three"
}, {
"CatID": 22,
"Currently": "is Four",
"ParentID": 16,
"Should": "should be Seven"
}, {
"CatID": 28,
"Currently": "is Five",
"ParentID": 16,
"Should": "should be Eight"
}, {
"CatID": 92,
"Currently": "is Six",
"ParentID": 18,
"Should": "should be Four"
}, {
"CatID": 30,
"Currently": "is Seven",
"ParentID": 92,
"Should": "should be Five"
}, {
"CatID": 95,
"Currently": "is Nine",
"ParentID": 30,
"Should": "should be Six"
}];
var localParentID = '';
var localArr = [];
for (var i in originalObject) {
var iObj = originalObject[i];
$('#displayDiv').append('Parent is ' + iObj['ParentID'] + ' ' + iObj['Currently'] + ' ' + iObj['CatID'] + ' ' + iObj['Should'] + '<br />');
}
Code (markup):
How can I sort the array above so that the ouput matches "should" order as opposed to "currently" order? It should be ordered by currently with should ParentID being attached to currently CatID.
Can't quite make this behave.