You can use .includes:

const good = ['beer', 'pizza', 'sushi']
const thing = 'pizza';
if (good.includes(thing)) console.log('hurray');

Note that this is entirely separate from Javascript's in operator, which checks for if something is a property of an object:

const obj = { foo: 'bar'}
const thing = 'foo';
if (thing in obj) console.log('yup');

Note that includes is from ES6 - make sure to include a polyfill. If you can't do that, you can use the old, less semantic indexOf:

const good = ['beer', 'pizza', 'sushi']
const thing = 'pizza';
if (good.indexOf(thing) !== -1) console.log('hurray');

Answer from CertainPerformance on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › i'm making a syntax cheatsheet for javascript vs. python
r/learnpython on Reddit: I'm making a syntax cheatsheet for Javascript vs. Python
July 13, 2023 -

I've been recently watching some Python videos and had the idea of making a simple cheatsheet comparing how to do the same basic things between two languages.

The cheatsheet assumes you are experienced in one of the languages and are looking to switch to the other and just need a quick reference. It doesn't try to teach you how to write either language because that's not the point.

https://www.theyurig.com/blog/javascript-python-syntax

I'm mainly just looking for someone with decent Python experience and who has the bare minimum Javascript experience (this is what I'm strong with) to help me build it and make it more robust. Because I want to offer a way to help with the least friction possible, you can just make a comment on the related issue on my repo and I'll add it.

Just be aware that I'm not gonna push change by change, but in bulks, so if you suggest something and it doesn't go live shortly afterward, it's most likely because I'm waiting to see if no more feedback is coming before I commit my current changes.

Post there since r/python is private due to protesting. Also, let me know if this specific request breaks rule #3 because I feel like it doesn't (since I'm creating a public resource) but I might just be wrong.

🌐
Object Computing
objectcomputing.com › resources › publications › sett › december-2020-comparing-python-and-javascript
Comparing Python and JavaScript: A Guide for Developers | Object Computing, Inc.
In Python 3.4, the asyncio library was added. It can be used to create coroutines which are similar to JavaScript Promises. The Python language doesn't provide the equivalent of the JavaScript promises, but libraries do.
Discussions

Do JavaScript arrays have an equivalent of Python’s “if a in list”? - Stack Overflow
If I have a list in Python, I can check whether a given value is in it using the in operator: >>> my_list = ['a', 'b', 'c'] >>> 'a' in my_list True >>> 'd' in my_list ... More on stackoverflow.com
🌐 stackoverflow.com
What is the python equivalence of javascript ${variable}?
`${variable}` in javascript roughly translates to f'{variable}' in Python. For example: >>> a = 12 >>> print(f'I have {a} friends :D') I have 12 friends :D Warning: using this to create database queries may be unsafe More on reddit.com
🌐 r/learnpython
4
1
June 16, 2021
node.js - Python's %s equivalent in Javascript? - Stack Overflow
For a few nice alternatives, you may want to take a look at JavaScript equivalent to printf/string.format · While it's asking for a C-like printf() equivalent for JS, the answers would also apply to your question, since Python format strings are inspired by C. More on stackoverflow.com
🌐 stackoverflow.com
Is there a JavaScript equivalent to Python's for loops? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... So I was dissapointed to find out that JavaScript's for ( var in array/object) was not equivalent to pythons for var in list:. More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › djangotricks › equivalents-in-python-and-javascript-part-3-4icc
Equivalents in Python and JavaScript. Part 3 - DEV Community
December 1, 2024 - ... You’re creating a false equivalency between arrow functions and lambda functions. Just because they look syntactically similar doesn’t mean that they have the same behavior.
🌐
Quora
quora.com › What-is-the-Python-equivalent-of-JavaScript-object
What is the Python equivalent of JavaScript object? - Quora
JavaScript has syntax like C and Java, while Python has a more stripped-down syntax with fewer special symbols. However, once one gets past the initial difference in appearances, the two languages have a lot in common.
🌐
GeeksforGeeks
geeksforgeeks.org › python › js-equivalent-to-python-in
Js Equivalent to Python In - GeeksforGeeks
August 5, 2025 - In JavaScript, we can use for...of for iterating over elements in arrays or strings, which is similar to Python's in used in a for loop.
Find elsewhere
🌐
Blogger
djangotricks.blogspot.com › 2019 › 02 › equivalents-in-python-and-javascript-bonus.html
DjangoTricks: Equivalents in Python and JavaScript. Bonus
February 2, 2019 - When you want to apply some function to a list of items to get a single result in one go, you can use the reduce function. It works for summing, multiplying, ORing, ANDing, or checking maximums and minimums. In Python there is a reduce() function for that. from functools import reduce items = [1, 2, 3, 4] total = reduce(lambda total, current: total + current, items) # 10 · In JavaScript there is a reduce() method of the array.
🌐
Real Python
realpython.com › python-vs-javascript
Python vs JavaScript for Pythonistas – Real Python
July 31, 2023 - Its rendering abilities can be especially useful for introspecting objects and tabular data, jumping to source code from a stack trace, or viewing HTML elements. You can log custom messages to the console using a predefined console object. JavaScript’s console.log() is the equivalent of Python’...
🌐
Runestone Academy
runestone.academy › ns › books › published › JS4Python › TheBasics › datatypes.html
2.6. JavaScript Data Types — JavaScript 4 Python Programmers
The second difference is the for loop. We’ll look in detail at the for loop later as there are many variations and subtle different kinds of for loops possible in JavaScript. for (let eachChar of s) is the best equivalent of the for eachChar in s used in Python.
🌐
Trey Hunner
treyhunner.com › js-like-python
JavaScript: Slightly more like Python
JavaScript **actually** has modules now. They're properly namespaced and they work pretty similarly to the way modules work in Python. Learn ES2015: https://babeljs.io/docs/learn-es2015/ ... So I just showed you a small handful of new features supported by JavaScript.
🌐
DEV Community
dev.to › massa142 › javascript-is-almost-pythonic-3f8
JavaScript is almost pythonic - DEV Community
December 12, 2017 - The constructor in Python is called __new__. Also, usually you override __repr__ to get a representation of the object instead of __str__. ... Don't have much inspiration for an original bio right now... ... Hmm... Good comparaison, JS is definitely getting better, but still. ... Everything is an Object in JS (including arrays), there isn't any proper equivalent of python's magic functions (add for example).
🌐
Blogger
djangotricks.blogspot.com › 2018 › 07 › equivalents-in-python-and-javascript-part-3.html
DjangoTricks: Equivalents in Python and JavaScript. Part 3
This time we will start looking into Python 3.6 and JavaScript based on the ECMAScript 6 standard. ECMAScript 6 standard is pretty new and supported only the newest versions of browsers.
🌐
DEV Community
dev.to › moz5691 › similar-functions-in-javascript-and-python--4kik
Similar functions in JavaScript and Python - DEV Community
November 27, 2018 - Map function between JavaScript and Python are almost identical. In JavaScript, forEach function does similar job but it is not used in some cases. map function is used instead where we need to create a new copy of object in a different memory ...
🌐
The Coding Walrus
thecodingwalrus.com › python › python-to-js-basics
Python to JavaScript Basics | The Coding Walrus
August 11, 2020 - Unlike JS, we can use the + operator to concatenate two lists. In JavaScript using the + operator converts the values to strings. Python lists have the append method which is the equivalent to JS Array's push method.
🌐
GeeksforGeeks
geeksforgeeks.org › python › javascript-equivalent-of-python-input
JavaScript Equivalent of Python Input - GeeksforGeeks
July 23, 2025 - In JavaScript, we can use the prompt() function to capture input from the user in a browser environment. The prompt() function is similar to Python’s input() and provides a text field for the user to enter a value.
🌐
Quora
quora.com › Is-there-a-Python-equivalent-to-JavaScripts-map-function
Is there a Python equivalent to JavaScript's map function? - Quora
Answer (1 of 4): Yes, Python has a map function as part of the built-in library. [code]>>> officers = [ ... { 'id': 20, 'name': 'Captain Piett' }, ... { 'id': 24, 'name': 'General Veers' }, ... { 'id': 56, 'name': 'Admiral Ozzel' }, ... { 'id': 88, 'name': 'Commander Jerjerrod' }] >>>...