Sorting JavaScript objects
Along with the ability to efficiently find objects that match a criteria, you will often require your objects to be in a certain order for outputting.
Getting ready
As with the previous recipe, create an HTML page named recipe-5.html
where we can add and execute JavaScript code for this recipe using the following code:
<!DOCTYPE html> <html> <head> <title>Chapter 3 :: AJAX & JSON</title> <script src="jquery.min.js"></script> <script > </script> </head> <body></body> </html>
Update the reference to the jQuery library in order to ensure that it includes the correct file on your computer.
How to do it…
Create a reusable function to sort a JavaScript object by performing the following step-by-step instructions:
Within the script tags in the
recipe-5.html
file you have just created, add the following JavaScript code:var people = [ { title: "Mrs", firstname: "Jane", lastname...