I'm receiving an array of objects like this (there are many fields i'm showing only the few):
dataset = [
{branchID : "IN123", customerID : "CB1234", customerName : "Alex", amountApplied : "1000.0"},
{branchID : "IN124", customerID : "CB1235", customerName : "Tom", amountApplied : "2000.0"},
{branchID : "IN128", customerID : "CB1236", customerName : "Adrian", amountApplied : "5000.0"}
]
I need to see the order of fields in this order
dataset = [
{branchID : "IN123", amountApplied : "1000.0", customerName : "Alex", customerID : "CB1234"}
{branchID : "IN124", amountApplied : "2000.0", customerName : "Tom" , customerID : "CB1235"}
{branchID : "IN128", amountApplied : "5000.0", customerName : "Adrian", customerID : "CB1236" }
]
i tried this :
var ordering = {},
sortOrder = ['branchID',,'amountApplied','customerName','customerID']
for (var i=0; i<sortOrder.length; i++)
ordering[sortOrder[i]] = i;
response.dataSet.sort( function(a, b) {
return (ordering[a] - ordering[b]) || a.localeCompare(b);
});
it shows .localCompare is not an function. any advice how to achvive this