Arrays and programming styles Flashcards
zero based array
- the first value in an array is 0, not 1
first slot would have an idea of 0
2nd slot would have an index of 1
3rd index would have an index of 2
etc..
array
a collection of values wrapped up under one named variable
programming language with a 1 based index (1)
visual basic
how to write an array in javascript (easy way)
var a = [ ]; a[0] = Apple; a[1] = iPod; a[2] = 77;
now, a[0] = Apple and so on.
how to write an array (fast way)
var a = [“Apple”, “iPod”, 77]; [0] [1] [2]
an array is often referred to as
a collection
in javascript, arrays are…
objects
if there are 5 items in an index, the highest # index is
4
0, 1, 2, 3, 4
method
a function that belongs to an object
what does the .reverse method do?
suppose:
a.reverse ( );
it would reverse the order of the array
Apple(0), iPad(1), 77(2)»_space; 77(0), iPad(1), Apple(2)
what does .sort method do?
suppose:
a.sort ( );
it would sort an array based on the rules of the programming language
alphabetical, numeric, or a mixture.
what does .join method do?
suppose:
a.join ( );
returns an array separated with commas as a character string
what does .pop method do?
suppose:
var b = a.pop ( );
would take the last value of an array, remove it from the array, and set b = the last value of the array that was just removed
what does .push method do?
suppose:
a.push (123);
123 would be added as a new index to he array in a new index slot
who wrote the “book” on javascript?
Mozilla, they own it.