Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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:
- a. store lists of data
- b. can store different data types at the same time
- c. are ordered so the position of each piece of data is fixed
- Example:
- var names = ["Mao","Gandhi","Mandela"];
- var sizes = [4, 6, 3, 2, 1, 9];
- var mixed = [34, "candy", "blue", 11];
- Syntax:
- var arrayName = [data, data, data];
- Any time you see data surrounded by [ ], it is an array.
- NOTE:
- Small complication: the position (or the index) of each bit of data is counted starting from 0, not 1.
- First element in the array: junk[0]
- Third element in the array: junk[2]
- Arrays have 0-based indexing, so we start counting the positions from 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement