Home » Programming » C# » Story Details
Printable Version

Array in JavaScript

by Manish Tewatia on Nov 30, 2011

JavaScript is a scripting language that will allow you to add real programming to your webpage.
Comments: 0    Views: 513

Introduction: JavaScript is a scripting language that will allow you to add real programming to your webpage. JavaScript is a client-side scripting language. This means the web surfer's browser will be running the script. JavaScript has been around for several years now in many different flavors. The main benefit of JavaScript is to add additional interaction between the website and its visitors with just a little extra work by the web developer. JavaScript allows industrious web masters to get more out of their website than HTML and CSS can provide and array is collection of similar type. JavaScript is most commonly used as a client side scripting language. This means that JavaScript code is written into an HTML page. When a user requests an HTML page with JavaScript in it the script is sent to the browser and it's up to the browser to do something with it.

Use of JavaScript:

  • Cookies
  • Control Browsers
  • Browser Detection
  • Validate Forms

JavaScript Array: Creating an array is slightly different from creating a normal variable. Because JavaScript has variables and properties associated with arrays, you have to use a special function to create a new array.:

  1. First way: This is the first way to declaration of array.
    var name=new Array();
    myCars[0]="manish";      
    myCars[1]="manu";
    myCars[2]="sonu";
  2. Second way: This is the second way to declaration of array.
    var  name=new Array("manish","manu","sonu");
  3. Theird Way: This is the Third way to declaration of array.
    var  name=["manish","manu","sonu"];

Example: The simple example of JavaScript in declare array is given below

Code:

     <html>
 
        <head>
 
            <title>Example of JavaScript </title>
 
            <script type="text/javascript">
 
                var arr = new Array(5);
                 arr[0] = "Manish";
                 arr[1] = "Sandeep";
                 arr[2] = "Amit";
                 arr[3] = "Rajesh";
                 arr[4] = "Arvind";
                 for (var i = 0; i < arr.length; i++) {
                     document.write("<b>arr[" + i + "] is </b>=>" + arr[i] + "<br>");
                 }
             </script
>
 
        </head>
 
        <body bgcolor="#ddcdff">
 
            <h2>
 
                This is my friends list
             </h2
>
 
        </body>
 
     </html>

Output: Open on browser

javascript.gif

Summary: This is the simple example that show how to declare array in a JavaScript. In a example we define a array of variable that name is "arr" and the size is five. In this example  we simply show friends name using a JavaScript.

Post a Comment
*
DevExpress PowerBuilder Web Development Windows Development Languages Software Engineering Databases
iPhone Architecture Secutiry UML & Modeling Operating Systems Networking Testing
Graphics Design Project Management Hardware Open Source Games Development Business Intelligence Visual Studio LightSwitch 2011
MonoDevelop Visual Studio 2010 ASP.NET HTML, DHTML XML PHP JavaScript
Silverlight Web Services WCF Windows Forms WPF Windows Services Dynamic Link Libraries
ActiveX COM, DCOM, ATL C# VB.NET C++ F# Java
Pascal SQL Server Oracle DB2 MS-Access Windows Servers Windows
Linux Unix SAP LINQ .NET Framework ADO.NET Reporting
Crystal Reports SQL Server Reporting Services Igenda Reports Active Reports Adobe Fireworks Arrays & Collections Hosting
Future Trends Android Windows Phone Smart Devices Business M&A Investment & Funding
Web Browsers Internet Explorer Firefox Safari Common Entrepreneurs Students
Consulting Wiki Gadgets MobileMe iCloud iOS Social Media
Facebook Twitter LinkedIn Google+ Microsoft Kinect XBox
Wii Playstation DirectX i OS OS X CIO, CTO, CEO Windows 8
Web Design Expression Blend 4 Photoshop CS5 Creative Suite 5.5 Expression Web 4 Expression Studio 4 Creative Suite® 5.5 Design
Creative Suite 5.5 Web Creative Suite 5.5 Production Startups Funding M&A Laptops Smart Phones
Desktops Cameras & Camcorders Netbooks Tablets Virtualization Microsoft Surface WordPress
Software Products Cloud Computing Current Affairs Technology TV TV
Earnings XAML E-Commerce MonoTouch Mono for Android Deals Electronics
Mobile Phone Laptop Tablet Book Computer Press Releases Reviews
Products Books Companies Windows Azure SQL Azure Interviews Mac
Web Browsers Symbian Windows Forms WPF Windows Services HTML 5 Office 365
SharePoint 2010 Exchange Server Adobe Visual Studio 2012 iPad Flex / Flash Games
Windows 9
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName