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



Download 0.78 Mb.
View original pdf
Page11/16
Date04.04.2022
Size0.78 Mb.
#58550
1   ...   8   9   10   11   12   13   14   15   16
chp15
15.2.8 Strings are NOT arrays
In many programming languages, text strings are represented as arrays of characters. While this makes sense in non- object oriented languages, there area number of advantages of representing data such as text as objects (see later this unit. You will only obtain undefined values if you attempt to refer to particular characters of Strings using the square bracket array indexing syntax.


8 For example, the code var firstName = "Matthew document.write("second letter of name is " + firstName[1]); It is also easy to confuse String and Array objects because they both have a length property. So the code var firstName = "Matthew document.write("second letter of name is " + firstName[1]); document.write("
length of 'firstName' " + firstName.length); is valid, and we do seethe number of characters of the String displayed However, the similarity is because both Strings and Arrays are objects — see later in this unit fora detailed discussion of JavaScript objects.

Download 0.78 Mb.

Share with your friends:
1   ...   8   9   10   11   12   13   14   15   16




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

    Main page