add(myArray, 'Second');
var newArray = ['Third','Fourth','Fifth'];
//Add the newArray object to the myArray
Array.addRange(myArray,newArray);
//Remove the last item from the Array
Array.removeAt(myArray, 4);
CHAPTER 4 ?– ASP.NET AJAX CLIENT LIBRARIES 56
DisplayArray(myArray);
}
function DisplayArray(arr) {
var i;
var strArray='';
for (i in arr)
{
strArray+=(i+':'+arr[i]+', ');
}
alert (strArray);
}
In this example, a classic JavaScript Array object is created and given a value (First)
at the initial index. After that, the add and addRange methods of the Array extension are
used to add additional values to the array. Then the last value of the array is removed
using the removeAt method, and the underlying Array object is passed to the DisplayArray
function to be displayed as shown in Figure 4-1. Once again, notice how the array object
here, myArray, is passed in as a parameter to methods of the Array extension. It??™s important
to realize that these additional methods listed in Table 4-1 are not new methods on
the native JavaScript Array object itself.
Pages:
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113