How to Convert Array Elements to UpperCase Or LowerCase using JQuery

No.of Views1661
Bookmarked0 times
Downloads 
Votes0
By  RRaveen   On  03 Jan 2011 01:01:27
Tag : JQuery , List Controls
In this snippet, I will show how to make all elements in array to UpperCase using JQuery. Recently I have published an article for display subcategories using JQuery AJAX with dropdown list, if you are aware of this, you can read here.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this snippet, I will show how to make all elements in array to UpperCase using JQuery. Recently I have published an article for display subcategories using JQuery AJAX with dropdown list, if you are aware of this, you can read here. So today I planned to display all sub categories in Uppercase too. But I’m not going to modify any server side code or Sql script to archive this features in existing application. So I decide to use the JQuery and done it. I would share that with you here.

Implementation

Let’s create simple web application with one page. The page has a div to print final result.Now add following code in order to implement.

Html Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to Convert Array Elements to UpperCase using JQuery</title>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

    <script language="javascript">
    $(document).ready(function ()
    {
        var larrays=["C#","asp.net","vb.net","sql server","sharepoint"];
            larrays=$.map(larrays, function(n)
                { 
                    return(n.toUpperCase());
                });
                $('#main').html(larrays.join("</br>"));
    });
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <div id="main">
        </div>
    </form>
</body>
</html>

As usual I have added Jquery libaray from Google. And then next script block within the document ready event, has declared a simple array with five elements.
Then use the .map() function to collect each item with changes into new array and then callback function to process each element. I have give Below .map() function details reference.

map(): http://api.jquery.com/jQuery.map/

Finally append all item from the array into the div with each item has break. Now run application and see output as like below.

Image Loading

Each item now is in UpperCase.

let's say make it lower case.just change the code as like below.

<script language="javascript">
    $(document).ready(function ()
    {
        var larrays=["C#","asp.net","vb.net","sql server","sharepoint"];
            larrays=$.map(larrays, function(n,i)
                { 
                    return(i+1+"-"+n.toLowerCase());
                });


                $('#main').html(larrays.join("</br>"));
    });
    </script>

One more additional features, let’s say you want to print each item with a sequence number. So you have to modify only on the callback function argument.
Javascript

<script language="javascript">
    $(document).ready(function ()
    {
        var larrays=["C#","asp.net","vb.net","sql server","sharepoint"];
            larrays=$.map(larrays, function(n,i)
                { 
                    return(i+1+"-"+n.toUpperCase());
                });
                $('#main').html(larrays.join("</br>"));
    });
    </script>

Now run and see the output.

Image Loading

That's all.Hopes help.

 
Sign Up to vote for this article
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popularSectionarticles
    Here i am going to discuss about on how to clear the file upload control using jQuery. To clear file upload control, you have to place file upload control within the DIV tag like below.
    Published Date : 02/Nov/2010
    Here I am looking to explain how to call page methods using jQuery.
    Published Date : 16/Apr/2010
    In this snippet, I will explain how to disable button after clicked once using JQuery. In the web application we have use the many buttons to do some specific operations.But sometimes users click many times in same button, this is giving unexpected results. So this snippet gives solutions to disable once click button and prevent unexpected result.
    Published Date : 19/Jan/2011
    In this snippet I will show you how to create numeric textbox using JQuery.This snippet is allow to enter numbers,backspace keys only.
    Published Date : 21/Jan/2011
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top