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


Creating arrays and assigning values to their



Download 0.78 Mb.
View original pdf
Page5/16
Date04.04.2022
Size0.78 Mb.
#58550
1   2   3   4   5   6   7   8   9   ...   16
chp15
15.2.3 Creating arrays and assigning values to their
elements
There area number of different ways to create an array. One piece of JavaScript code that creates such an array is as follows
// VERSION 1 var weekDays = new Array weekDays[0] = "Monday weekDays[1] = Tuesday weekDays[2] = "Wednesday weekDays[3] = "Thursday weekDays[4] = "Friday weekDays[5] = "Saturday weekDays[6] = Sunday The first (non-comment) line is var weekDays = new Array


4 This line declares anew variable called weekDays and makes this new variable refer to anew Array object that can hold seven elements.
Note
The concept of arrays as objects is discussed later this unit. The seven statements that follow this line assign the Strings "Monday" - "Sunday" to the array elements
weekDays[0] to weekDays[6] respectively.

Download 0.78 Mb.

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




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

    Main page