title: "How to check if item in list/array (Python and Javascript)" date: "2019-01-21" categories: - "how-to" coverImage: "sophia-baboolal-86224-unsplash.jpg"
I'm going to try something new this week. I've always had the intention of writing down a series of common syntax for Python and Javascript. Because I keep looking them up anyway. So I thought, this would be a good opportunity to try writing them out as two separate Series. One for the Weekly Post and one for How to X in Python and Javascript. In this post, I will touch on how to find an item in a list.
Situation: You have a list (Python's preferred term) or array (Javascript's preferred term) of items. For a simple example, let's just use a list of numbers [1, 2, 3]
. You want to find out if the number 3
is in the list. Hence, you need a boolean result.
3 in [1, 2, 3]
arr = [1, 2, 3]
arr.includes(3)
This is post #5 in my quest for publishing weekly.
Photo by Sophia Baboolal on Unsplash