I have an issues with sorting on non-Latin strings of array object.
I have used this _.sortBy(object, 'name') in my code to sort on name.
Here is my array for Persian text:
[['id':1,'name':'ب'],['id':2,'name':'ج'],['id':3,'name':'اما']]
And output should be like this after sorting:
['id':3,'name':'اما'],['id':1,'name':'ب'],['id':2,'name':'ج']
But it's not giving this output. Does anyone have idea about this?
First you need to correct your Array. It has an invalid format.
var a = [{'id':1,'name':'ب'},{'id':2,'name':'ج'},{'id':3,'name':'اما'}];
a.sort(function(a, b) {
if (a.name > b.name) {
return true;
}
});
Input: [{'id':1,'name':'ب'},{'id':2,'name':'ج'},{'id':3,'name':'اما'}]
Output: [{'id':3,'name':'اما'},{'id':1,'name':'ب'},{'id':2,'name':'ج'}]
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