Working with Javascript Array

Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 728
Hi All,

Today we will learn about Working with Javascript Array.

So, an Array is a special kind of variable in Javascript,which holds multiple values at a time.

It's so easy to declare an Array in Javascrtipt.As we know that Array index will be starting from 0.

For Example:-

<script type="text/javascript" language="javascript">
function javascript_array()
//defining an Array
var employee = new Array();
employee[0] = "Vishal";
employee[1] = "Kumar";
employee[2] = "Neeraj";
employee[3] = "Pune";
employee[4] = "9876512345";

//Now accessing a value from an Array
var value = employee[0];

alert(value); //Output will be Vishal

//Now changing the value of first element
employee[0] = "Vinay";

alert(employee[0]); //Output will be Vinay

//Array.Length and Array.IndexOf works exactly like Dot Net
var array_length = employee.length;
var find_string = employee.indexOf("Neeraj");

alert(array_length); //Output will be 5 as employee has 5 element.
alert(find_string); //Output will be 2 as Neeraj is the 3rd element but Array index starts from 0

//Convert employee Array into String as with the help of toString() method
alert(employee.toString()); //Output will be Vishal,Kumar,Neeraj,Pune,9876512345

Comments or Responses

Login to post response