Friday, July 26, 2013

Arrays


<script>
var beatles = new Array("johny", "george", "ringo", "paul", "paul2");
document.write(beatles[3] + " is dead");//access the array index
</script>
##############################################################
Picture of The Beatles — Hi-res 1280x784: http://userserve-ak.last.fm/serve/_/25926775/The+Beatles+the+walrus+wasnt+paul.jpg
<script>

var beatles = new Array(3);
beatles[0] = "john";
beatles[1] = "george";
beatles[2] = "ringo";
beatles[3] = "paul";
beatles[4] = "paul2";
document.write(beatles[3] + " is dead");
</script>
//You can't always enter all your information into your array as soon as you create it, and you might not know how many items the array will include,

<script>
var myClasses = new Array();
 myClasses[0] = "Web 110: A+";
myClasses[1] = "Web 120: A+";
myClasses[2] = "ITC 280: A+";
myClasses[3] = "Web 150: A+";
myClasses[4] = "Math 85: F-";
myClasses[5] = "Phil 106: A-";
//Arrays are objects and have Properties and Methods.
 document.write(myClasses.length);
</script>

An Associative Array uses strings instead of numbers as an index


<script>
var weather = new Array();
weather["seattle"] = "party cloudy";
weather["portland"] = "chance of rain";
weather["los angeles"] = "Who Cares";

document.write("The weather will be " + weather["portland"] + " today in Portland.");
</script>

Whatever

No comments:

Post a Comment