Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 22 / 68

Searching an array (in)

This lesson covers searching an array with Julia's in operator, with the aim of checking whether a value is present.

value in array tells you whether the value is in the array. It reads almost like plain English.

The sample code checks whether "orange" is in the array with "orange" in fruits. The in keyword doubling as an operator is part of what makes Julia readable.

A common early stumble is that the search takes longer as the data grows. With a lot of data, searching a Set is faster.

In professional work, this search comes up whenever you check whether an array contains a particular value.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)