0
0
Swiftprogramming~5 mins

Array operations (append, insert, remove) in Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the append() method do in a Swift array?
It adds a new element to the end of the array, increasing its size by one.
Click to reveal answer
beginner
How do you insert an element at a specific position in a Swift array?
Use the insert(_:at:) method, specifying the element and the index where you want to add it.
Click to reveal answer
beginner
What happens when you use remove(at:) on a Swift array?
It removes the element at the specified index and shifts the remaining elements to fill the gap.
Click to reveal answer
beginner
If you want to remove the last element of a Swift array, which method do you use?
Use removeLast() to remove and return the last element of the array.
Click to reveal answer
intermediate
Can you append multiple elements to a Swift array at once? If yes, how?
Yes, use the append(contentsOf:) method with another array or sequence of elements.
Click to reveal answer
Which method adds a single element to the end of a Swift array?
Apop()
Binsert()
Cremove()
Dappend()
How do you add an element at index 2 in a Swift array named 'fruits'?
Afruits.insert("apple", at: 2)
Bfruits.remove(at: 2)
Cfruits.append(2)
Dfruits.add(at: 2)
What does remove(at: 0) do to an array?
ARemoves the first element
BRemoves the last element
CRemoves all elements
DAdds an element at the start
Which method removes and returns the last element of a Swift array?
AdeleteLast()
BremoveFirst()
CremoveLast()
DpopLast()
How can you add multiple elements to a Swift array at once?
AinsertMultiple()
Bappend(contentsOf:)
CaddAll()
DappendAll()
Explain how to add, insert, and remove elements in a Swift array with examples.
Think about how you add things to a list, put things in the middle, or take things out.
You got /4 concepts.
    Describe the difference between append() and insert(_:at:) in Swift arrays.
    One adds to the end, the other lets you choose the spot.
    You got /4 concepts.