Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. Variables can store numbers or strings. But so far, we've only been able to store ONE number or ONE string. Good thing we have arrays. Arrays:
  2.  
  3. a. store lists of data
  4. b. can store different data types at the same time
  5. c. are ordered so the position of each piece of data is fixed
  6.  
  7. Example:
  8.  
  9. var names = ["Mao","Gandhi","Mandela"];
  10.  
  11. var sizes = [4, 6, 3, 2, 1, 9];
  12.  
  13. var mixed = [34, "candy", "blue", 11];
  14. Syntax:
  15. var arrayName = [data, data, data];
  16.  
  17. Any time you see data surrounded by [ ], it is an array.
  18.  
  19.  
  20.  
  21.  
  22. NOTE:
  23.  
  24. Small complication: the position (or the index) of each bit of data is counted starting from 0, not 1.
  25.  
  26. First element in the array: junk[0]
  27. Third element in the array: junk[2]
  28. Arrays have 0-based indexing, so we start counting the positions from 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement