Home Sort array of objects by string property value in JavaScript
Reply: 0

Sort array of objects by string property value in JavaScript

user479
1#
user479 Published in May 25, 2018, 11:10 am

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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.552675 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO