0

I am trying to sort array of object using this link Sort array of objects by string property value in JavaScript

Sorting an array of JavaScript objects

and but when I try to sort it is not giving the expected result here is my code https://jsfiddle.net/36wp6b98/

Expected out put is this

[
    {
        Name: "1009834",
        Account__r: "Ad Imperial Bank",
        PO__c: "PO9957",
        Dispute__c: "-",
        Amount__c: "8182.62",
        Expected_Payment_Date__c: "Tue May 05 2015",
        Disputed_Amount__c: "0.00",
        Promised_Amount__c: "9006.80",
        Promise_Date__c: "Wed Jul 02 2014",
        Balance__c: "8182.62",
        Close_Date__c: "-",
        id: "a0RK0000002l366MAA"
    },
    {
        Name: "1009092",
        Account__r: "Canadian Imperial Bank",
        PO__c: "PO9215",
        Dispute__c: "-",
        Amount__c: "9370.98",
        Expected_Payment_Date__c: "Fri Jul 31 2015",
        Disputed_Amount__c: "0.00",
        Promised_Amount__c: "8695.90",
        Promise_Date__c: "Thu Mar 06 2014",
        Balance__c: "9370.98",
        Close_Date__c: "-",
        id: "a0RK0000002l365MAA"
    },
    {
        Name: "1008082",
        Account__r: "pacd Imperial Bank",
        PO__c: "PO8205",
        Dispute__c: "-",
        Amount__c: "4696.52",
        Expected_Payment_Date__c: "Tue May 05 2015",
        Disputed_Amount__c: "0.00",
        Promised_Amount__c: "0.00",
        Promise_Date__c: "-",
        Balance__c: "4696.52",
        Close_Date__c: "-",
        id: "a0RK0000002l364MAA"
    }

]

Code

function compare(a,b) {
  if (a.last_nom < b.last_nom)
    return -1;
  if (a.last_nom > b.last_nom)
    return 1;
  return 0;
}
var b=obj.sort(function(a, b) {
    return a.Account__r - b.Account__r;
})
console.log(b)
Community
  • 1
  • 1
Shruti
  • 1,554
  • 8
  • 29
  • 66

0 Answers0