I have a long array of pks. Which has been converted into a json object pk:count
This how I created it
var count = {};
topPKs=[];
topPKs.push(pk1);
topPKs.push(pk2);
topPKs.push(pk3);
topPKs.push(pk1);
topPKs.push(pk1);
$.each(topPKs, function(key, value) {
if(!count[value])
count[value] = 1;
else
count[value]++;
});
This is how it looks in console:
Object
511909695: 3
523212317: 2
530009912: 3
532408581: 2
533498979: 1
555813096: 1
574723371: 1
574938523: 1
580120684: 6
584152864: 2
There is an object array with pk and name. So when I say Object.pk, it returns pk value.
Not all pks in the second object array present in the first object with pk:count.
0: Object
pk: "609819451"
name: "Some Name"
1: Object
2: Object
Now I want to sort second object array based on the pk count present in the first object. I am not sure how would traverse through all the pks in the first object. Because it is not an array. Should I create it a different way?
- How would I traverse the first object with jquery?
- How would I sort the second object array based on the count of pk in first PK?