.contains()
Published Oct 11, 2022Updated May 26, 2023
Contribute to Docs
The .contains()
method returns true if an array contains a specified element, false otherwise.
Syntax
arrayName.contains(element)
Example
var topBabyNames = ["Sophia", "Liam", "Riley", "Jackson", "Olivia", "Noah"]print(topBabyNames.contains("Olivia"))// Output: true
Note: Big-O of this method is O(n).
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.