I have two arrays
[60 80 82 50 80 80 ][ A B C D E F ]I need to get top two brands based on MRP. highest two in MRP is 82 ,80 but 80 is 3 times repeated so i need all repeated values as well to get top two brands. i.e i need to display [C B E F]
For that i sorted MRP in descending order.Now MRP after sorting become [ 82 80 80 60 50 ]
Now i need to sort Brand Array based on Sorted MRP.Can some one help in this sorting using javascript .
Try below code
var A = [60, 80, 82, 50, 80, 80];
var B = ['a', 'b', 'c', 'd', 'e', 'f'];
var all = [];
for (var i = 0; i < B.length; i++) {
all.push({ 'A': A[i], 'B': B[i] });
}
all.sort(function(a, b) {
return b.A - a.A;
});
A = [];
B = [];
for (var i = 0; i < all.length; i++) {
A.push(all[i].A);
B.push(all[i].B);
}
alert(A);
alert( B);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With