HTML and CSS Reference
In-Depth Information
Figure 12-11
Methods of javascript arrays
Array Method
array .concat( array1 , array2 ,...)
Joins array to two or more arrays, creating a single
array containing the items from all the arrays.
array .join( separator )
Joins all items in array into a single text string.
The array items are separated using the text in the
separator parameter. If no separator is specified, a
comma is used.
array .pop()
Removes the last item from array .
array .push( values )
Appends array with new items, where values is a
comma-separated list of item values.
array .reverse()
Reverses the order of items in array .
array .shift()
Removes the first item from array .
array .slice( start , stop )
Extracts the array items starting with the start index
up to the stop index, returning a new subarray.
array .splice( start , size , values )
Extracts size items from array starting with the item
with the index start . To insert new items into the
array, specify the array items in a comma-separated
values list.
Sorts array where function is the name of a function
that returns a positive, negative, or 0 value. If no func-
tion is specified, array is sorted in alphabetical order.
array .sort( function )
array .toString()
Converts the contents of array to a text string with the
array values in a comma-separated list.
array .unshift( values )
Inserts new items at the start of array , where values
is a comma-separated list of new values.
You set up the first parts of the online calendar in this session. In the next session, you'll
complete the monthly calendar by working with loops and conditional statements.
Session 12.1 Quick Check
1. What is an array?
2. Provide a command to create an array named dayNames using the object con-
structor form.
3. Provide a command to create and populate the dayNames array with the abbre-
viations of the seven days of the week (starting with Sun and going through Sat ).
Use the array literal form.
4. Provide a command to return the third value from the dayNames array.
5. Provide a command to sort the dayNames array in alphabetical order.
6. Provide a command to extract the middle five values from the dayNames array.
7. Provide a command to create a multidimensional array named myArray for the
following matrix:
- 2
- 8
- 3
Search WWH ::

Custom Search