What is an array?
Learn what arrays and lists are and how we use them in coding.
1 - What is an array?
An array or list is a group of values stored in a collection. These values may be added to, changed or rearranged.
For example in a game we could have an array called "top scores" and this would store the 10 highest scores of the game along with the player's name.
- 482 - Gamerboy
- 470 - SteveO
- 465 - NinJane
- 430 - Zeplin
- 382 - Speedster
2 - Changing the items
Once we create an array we can:
- Add items to it add 465 - NinJane to [top scores]
- Delete items from it delete 1 of [top scores] (where 1 is the index of the item you want to delete)
- Delete all of the items in the array delete all of [top scores]
- Retrieve an item from the array item 1 of [top scores]
- Get the amount of items in the array length of [top scores]
- Check if it contains a specific item [top scores] contains thing ?
- Replace an item in an array with a different item replace item 1 of [top scores] with thing
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.