Day 3 and 4 Flashcards
(5 cards)
What is array ? and how to make one ? example -
Arrays are their own data type. It’s a list of data -all of the same data type., could be a list of strings , int ,double .
start and end arrays using square brackets, with commas between every item
var beatles = [“John”, “Paul”, “George”, “Ringo”]
What is index ? what does it help do ?
var beatles = [“John”, “Paul”, “George”, “Ringo”]
what would you do to print John using index ?
The position of an item in an array is commonly called its index.
It helps reading values out from an array, we ask for values by the position they appear in the array.
print(beatles[0])
0 because counting starts from 0 in swift.
How to add new item in array ?
var beatles = [“John”, “Paul”, “George”, “Ringo”]
1. add name Adrian to it.
.append()
beatles.append(“Adrian”)
create an empty array of scores and add items one by one ?
use : Array<Int>
t’s an array that holds integers. allows swift to know for sure that it always should be integer and stops us from adding others.</Int>
var scores = Array<Int>()
scores.append(100)
scores.append(80)
scores.append(85)
print(scores[1])</Int>