Home | | Internet & World Wide Web HOW TO PROGRAM | | Internet Programming | | Web Programming | Declaring and Allocating Arrays - JavaScript(JS)

Chapter: Internet & World Wide Web HOW TO PROGRAM - The Ajax Client - JavaScript: Arrays

| Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail |

Declaring and Allocating Arrays - JavaScript(JS)

Arrays occupy space in memory. Actually, an array in JavaScript is an Array object.

Declaring and Allocating Arrays

 

Arrays occupy space in memory. Actually, an array in JavaScript is an Array object. The programmer uses operator new to allocate dynamically (request memory for) the number of elements required by each array. Operator new creates an object as the program executes by obtaining enough memory to store an object of the type specified to the right of new. The process of creating new objects is also known as creating an instance or instantiating an object, and operator new is known as the dynamic memory allocation operator. Arrays are allocated with new because arrays are considered to be objects, and all objects must be created with new. To allocate 12 elements for integer array c, use the statement

 

var c = new Array( 12 );

 

The preceding statement can also be performed in two steps, as follows:

 

var c; // declares the array

 

c = new Array( 12 ); // allocates the array

 

When arrays are allocated, the elements are not initialized—they have the value undefined.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.