Chapter 15. JavaScript 4: Objects and Arrays Table of Contents


Displaying the contents of arrays



Download 0.78 Mb.
View original pdf
Page7/16
Date04.04.2022
Size0.78 Mb.
#58550
1   2   3   4   5   6   7   8   9   10   ...   16
chp15
15.2.5 Displaying the contents of arrays
The easiest way to display the contents of an array is to simply use the document.write() function. This function, when given an array name as an argument, will display each element of the array on the same line, separated by commas. For example, the code var weekDays = new Array "Monday, "Tuesday, "Wednesday, "Thursday, Friday, "Saturday, "Sunday document.write( " Weekdays " + weekDays); Produces the following output in a browser
15.2.6 Array length
The term length, rather than size, is used to refer to the number of elements in array. The reason for this will become clear shortly. As illustrated in the VERSION 1 code above, the size of an array can be specified when an array is declared var weekDays = new Array


5 This creates an array with seven elements (each containing an undefined value

Download 0.78 Mb.

Share with your friends:
1   2   3   4   5   6   7   8   9   10   ...   16




The database is protected by copyright ©ininet.org 2024
send message

    Main page