A. Define Array
Hi... Welcome in Mysite in "We ArE KnOwLeDGe"...
You know of array..? In
javascript too present array operation. And Array isc likely mono variable or
one variable with many element with same of type.
Example form of array:
Book[1]= “computer”
Book[2]= “economy”
Book[3]= “science”
Book[4]= “logic”
Book[5]= “Accountancy”
How To Made Array In Javascript ?
Fristly for made array we must declarasion variable array
with
Sintak:
New array()
1. In
made variable of array be more specification, like as :
2. Name
variable must start from Letter character.
3. Not
be space (if you will using space use underscore(_)
4. Not
using special character
Example 1:
<html>
<head>We Are
Knowledge<br>
<title>Tutorial
Javascript - Array</title>
</head>
<body>
<script type =
"text/javascript">
var
hardware = new Array()
hardware[0] =
"VGA"
hardware[1] =
"RAM"
hardware[2] =
"HDD"
for
(a=0;a<hardware.length;a++)
{
document.write(hardware[a]
+ "<br />")
}
</script>
</body>
</html>
To result :
VGA
RAM
HDD
Example2
<html>
<head>We Are
Knowledge<br>
<title>Tutorial
Javascript - Array</title>
</head>
<body>
<script type =
"text/javascript">
var
hardware = new
Array("VGA", "RAM", "HDD");
document.write(hardware[2])
</script>
</body>
</html>
Look on example 2 red color number “2” . Want to result “RAM”.
If you change ”1” or “3” to result is “VGA” or ”HDD”
B. Method Manipulation For Array
Properties
|
Define
|
Length
|
To result count element in
array
|
concat
|
For fushion more than one
array
|
Pop
|
For remove or delete last
element array
|
Reverse
|
For requeue element in array
|
Shift
|
For delete first element in
array
|
Short
|
For queue element of array
|
Sintaks Array:
arrayObject.concat(arrayX, arrayX, ……., arrayX,)
example:
<html>
<head>We Are
Knowledge<br>
<title>Tutorial
Javascript - Array</title>
</head>
<body>
<script type =
"text/javascript">
var
a = new Array(3)
a[1] = "we"
a[2] = "are"
a[3] =
"knowledge"
var
b = new Array(3)
b[1] =
"have"
b[2] = "fun"
b[3] =
"enjoy"
var
c = new Array(3)
c[1] =
"lets"
c[2] =
"site"
c[3] = "in my
page"
document.write(a.concat(b,c))
</script>
</body>
</html>
And result :
“,we,are,knowledge,,have,fun,enjoy,,lets,site,in my page”
Ok... Just it...
Thanks for visitors...
No comments:
Post a Comment