Powered by Blogger.

Monday, February 24, 2014

Create Array in javascript




Here in this article, we will discuss about Creating Arrays in javascript. Also you can check out some posts on:

- Delete all stored procedures at once in SQL Server database

- Static Keyword in C#.Net

- How to implement FileUpload Control in Update Panel using asp.net?

JavaScript supports a more complicated data type known as an array. An array is a collection of individual values grouped together. An array essentially contains a series of numbered containers into which you can place values. Each container can contain a string, a number, or any other data type.

To create a new array, you create a new instance of the Array object:

var arrayName = new Array(number of elements);

The number of elements is just the initial number of elements in the array; you can add more on the fly as you work with the array, but it is a good idea to initialize the array with the likely number of elements you will use.

1. Open a new HTML document in your preferred HTML or text editor.

2. Create the head of the document with opening and closing head
tags:
<head>

</head>

3. Insert a script block in the head of the document:

<head>
        <script language="JavaScript">
<!--
// -->
        </script>
    </head>

4. Create a variable named myArray and initialize it as a new array with five elements:

<body>
        <script language="JavaScript">
<!--
            var myArray = new Array(5);
// -->
        </script>
    </body>

5. Save the file and close it.



0 comments

Post a Comment