0

My new post: Hi All, This time I made correct changes to the array of objects with adding "]". Now how do I sort according to value?

I am not sure how to sort out objects, though I have seen it like arrays or objects. It does not seem to work. Please advise

var storeData3 = 
  [{ 'key' : 'value1',
   'key' : 'value2' ,
   'key' : 'value3' ,
   'key' : 'value10'}];

storeData3.push({'key':'value6'}); 

Any idea?

user1739825
  • 820
  • 4
  • 10
  • 27

1 Answers1

0

Your storeData3 should like this

var storeData3 = [
  { 'key' : 'value1' },
  { 'key' : 'value2' },
  { 'key' : 'value3' },
  { 'key' : 'value4' }
]

storeData3.push(  { 'key' : 'value5' });
Jeff Lee
  • 783
  • 9
  • 17
  • Thanks but actually i just want to sort according to valueX, ie in the ascending or descending order after the element has been push, say value6 in my old code. – user1739825 May 23 '13 at 05:58
  • 1
    Hi Thanks Now found a way with help from [link]( http://www.javascriptkit.com/javatutors/arraysort2.shtml) – user1739825 May 23 '13 at 08:00
  • Woooo @@" hahaha I can find it, But I am trying to write my own function. But that is good. :D good luck – Jeff Lee May 23 '13 at 08:11