Skip to Content
Learn
Arrays
.count Property

Properties in Swift, allow us to access a value that is specific to a particular structure. We can use the .count property of an array to give us a number value of elements inside the array.

For example, suppose we have an array called grocery with some emojis:

var grocery = ["πŸ₯“", "πŸ₯ž", "πŸͺ", "πŸ₯›", "🍊"]

When we print out grocery.count:

print(grocery.count)

The output will look like this:

5

This property will come in extra handy when the array is lengthy.

Instructions

1.

It takes too long to count the number of elements in countingRhyme with your eyes.

Print the size of the array using .count.

Folder Icon

Take this course for free

Already have an account?