Skip to main content
typo ;)
Source Link
Adam
  • 5.3k
  • 3
  • 33
  • 64

I have an array of JavaScript objects:

var objs = [ { first_nom: 'Lazslo''Laszlo', last_nom: 'Jamf' }, { first_nom: 'Pig', last_nom: 'Bodine' }, { first_nom: 'Pirate', last_nom: 'Prentice' } ]; 

How can I sort them by the value of last_nom in JavaScript?

I know about sort(a,b), but that only seems to work on strings and numbers. Do I need to add a toString() method to my objects?

I have an array of JavaScript objects:

var objs = [ { first_nom: 'Lazslo', last_nom: 'Jamf' }, { first_nom: 'Pig', last_nom: 'Bodine' }, { first_nom: 'Pirate', last_nom: 'Prentice' } ]; 

How can I sort them by the value of last_nom in JavaScript?

I know about sort(a,b), but that only seems to work on strings and numbers. Do I need to add a toString() method to my objects?

I have an array of JavaScript objects:

var objs = [ { first_nom: 'Laszlo', last_nom: 'Jamf' }, { first_nom: 'Pig', last_nom: 'Bodine' }, { first_nom: 'Pirate', last_nom: 'Prentice' } ]; 

How can I sort them by the value of last_nom in JavaScript?

I know about sort(a,b), but that only seems to work on strings and numbers. Do I need to add a toString() method to my objects?

edited tags
Link
dreftymac
  • 32.6k
  • 27
  • 125
  • 191
edited tags
Link
Kamil Kiełczewski
  • 93.7k
  • 34
  • 401
  • 375
added 4 characters in body; edited tags; edited title
Source Link
Alexander Abakumov
  • 14.7k
  • 16
  • 99
  • 135
Loading
edited tags
Link
Harshal Yeole
  • 5k
  • 1
  • 24
  • 43
Loading
Question Protected by Pankaj Parkar
Question Unprotected by Pankaj Parkar
edited tags; edited title
Link
Bergi
  • 670.6k
  • 162
  • 1k
  • 1.5k
Loading
clean title and formatting of code snippet
Source Link
Web_Designer
  • 75.1k
  • 93
  • 210
  • 268
Loading
Question Protected by CommunityBot
deleted 11 characters in body
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134
Loading
Source Link
Tyrone Slothrop
  • 42.6k
  • 3
  • 19
  • 8
Loading