Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 4630 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > jQuery > Sort Elements of Array in Alphabetical Order ...
Self-Innovator

Sort Elements of Array in Alphabetical Order

 Code Snippet posted by: Self-Innovator | Posted on: 4/12/2012 | Category: jQuery Codes | Views: 848 | Status: [Member] | Points: 40 | Alert Moderator   
Ads

Using jQuery Sort the names of an arry in Alphabetical Order

<form id="form1" runat="server">

<div id="main1">
</div>
<div id="main2">
</div>
</form>


jQuery Script Code
$(document).ready(function() {

var members = [
{ "name": "CM Punk", "id": 003, "email": "punk@wwewreslt.com" },
{ "name": "The Mizery", "id": 004, "email": "miz@awesome.com" },
{ "name": "John Lunaritics", "id": 001, "email": "lunaritics@hotmailcom" },
{ "name": "Jessica", "id": 002, "email": "Jessie@gmailcom" },
{ "name": "Salman", "id": 005, "email": "sallubhwanted@bollywoodstar.com" }
];

$.each(members, function(index, value) {
$("#main1").append("<p><strong>Id:</strong>" + value.id + "- <strong>Name:</strong>" + value.name + "- <strong>Email:</strong>" + value.email + "</p>");
});
members = members.sort(function(a, b) {
if (a.name < b.name) { return -1 };
if (a.name > b.name) { return 1 };
return 0;
});
$.each(members, function(index, value) {
$("#main2").append("<p><strong>Id:</strong>" + value.id + "- <strong>Name:</strong>" + value.name + "- <strong>Email:</strong>" + value.email + "</p>");
});
});


Join Hands Change lives
Thanks & Regards
Straight Edge Society
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/18/2013 6:16:49 PM