php-mysql tutorial

Designed By NISHANT GUPTA

  • Home
  • PHP
  • HTML
  • CSS
  • JavaScript
  • JQuery
  • Contact-us
  • Learn HTML

    • Introduction of HTML
    • Image Handling in HTML
    • List Handling in HTML
    • Font Handling in HTML
    • Table Handling in HTML
    • Form Handling in HTML
  • Learn CSS

    • Introduction of CSS
    • Styling Background in CSS
    • Styling Text in CSS
    • Styling Font in CSS
    • Styling Link in CSS
    • Styling List in CSS
    • Styling Table in CSS
    • Styling Div in CSS
    • Styling Span in CSS
    • Positioning in CSS
    • Display in CSS
  • Learn JavaScript

    • Introduction of JavaScript
    • Data Type in JavaScript
    • Variable in JavaScript
    • Oprator in JavaScript
    • Cond. Statement in JavaScript
    • Loop in JavaScript
    • Array in JavaScript
    • Function in JavaScript
    • Date in JavaScript
    • String in JavaScript
    • DOM in JavaScript
    • Event Handling in JavaScript
    • Form Handling in JavaScript
  • Learn PHP-MYSQL

    • Introduction of PHP
    • Decision Control in PHP
    • Loop in PHP
    • Array in PHP
    • Function in PHP
    • Form Handling in PHP
    • File Inclusion in PHP

Array in JavaScript

Array Definition
  1. In JavaScript arrays are different from arrays of other languages.
  2. Traditionally an array is considered to be a collection of homogeneous elements, which means that it cannot contain dissimilar elements.
  3. But JavaScript does not follow this concept.
  4. A JAVASCRIPT ARRAY CAN CONTAIN HETROGENEOUS ELEMENTS
  5. Thus we can say that arrays in JavaScript are similar to structure of C language except that they are accessed using an index.

Creating An Array

We can create an array in 2 ways:
  1. Using Array Literal.
  2. 1.Using Array Constructor.

Array Literals

Array literals are written using [   ] containing array elements separated with commas.

Syntax

var <array name>=[value,value,. . . ];

Example:

var nums=[2,5,8,3,9];

var colors=[“red”,”green”,”blue”];

Another way of using Array Literals is that we can leave the [ ] empty and fill values afterwards.

For Example

var num=[ ]; /* declares the array */

num[0]=2;  /* initializes it */

num[1]=5;

num[2]=8;

num[3]=3;

num[4]=9;

Array With “undefined” Values

For Exaple

var colors=[“red”,   ,   ,”green”,”blue”];

The above array has 5 elements, from colors[0] to colors[4]. But since colors[1] and colors[2] have not been initialized they are automatically set to "undefined"

Using “length” Property

JavaScript arrays are Objects and hence they have some predefined properties and methods which help makes it easier for a programmer to handle them.

The “length” property returns the size of the array.

For Example

var nums=[2,5,3,8,6,9];

alert(nums.length); // will show 6

 

 

 

 

 

Advertisements

 

©  2014 All Rights Reserved  •  Design by >Nishant Gupta.

Privacy Policy • Terms of Use