![]() |
Updated 07/18/14 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Using Arrays This section will demonstrate the use of different kinds of arrays and array methods. An array is a set of related objects. I'll provide a demonstration below. I'll create a simple array of sport types Now we will try using a few Array methods the first one is the reverse method. <body><script type="text/javascript"><!--
// Here is the array the numbers 1 through 5 The above script produces the following result: Now let's try another array method here we will try the array shift method which will a pop the first element from the sports array and returns it. You can use the following code:
<script type="text/javascript"> // Using the array pop method
Now one more final array method using the same sports array above. Here we will use the array method join which will join a string with the specified string separator. In this example we use the dash symbol ("-") as the string separator. These array methods basically work the same, you use the arrayName.arrayMethod; format. For example ( arrayName.join(); ) or for the array below <script type="text/javascript"> //Array name is sports and the array method used here
is join() Now try creating your own JavaScript Array and use atleast one Array method. You can find a list of all the array methods at www.devguru.com |
This site was last updated 07/08/14