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.:
- First way: This is the first way to
declaration of array.
var name=new Array();
myCars[0]="manish";
myCars[1]="manu";
myCars[2]="sonu"; - Second way: This is the second way
to declaration of array.
var name=new Array("manish","manu","sonu"); - 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

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.