0

I have an array of objects like:-

myobject[
  {name:'Zeta' ,count:1},
  {name:'Nei',count:20},
  {name:'tri',count:3)

];

I want object with the name tri to appear as first object instead of third. how can i do that?

separ1
  • 205
  • 2
  • 20
  • 1
    http://stackoverflow.com/a/1129270/1544886 or https://docs.angularjs.org/api/ng/filter/orderBy – K Scandrett Mar 01 '17 at 19:56
  • 1
    atleast do a google search before asking here – rakesh Mar 01 '17 at 19:59
  • I don't know how you could achieve that since small letters are after the capital letters in the ASCII table. The 'tri' word will be always after the words that starts capital letters.If you want to use alphabetical order that your should ignore case when you do sorting of your array. – Luci Mar 01 '17 at 19:59
  • @luci you can write your own sort function and choose to ignore case. Refer to my first link above – K Scandrett Mar 01 '17 at 20:01
  • myobject.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }); – Luci Mar 01 '17 at 20:07

0 Answers0