Book Image

jQuery 2.0 Development Cookbook

By : Leon Revill
Book Image

jQuery 2.0 Development Cookbook

By: Leon Revill

Overview of this book

Table of Contents (17 chapters)
jQuery 2.0 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. 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...