DEV Community

python to javascript

abdelwahed on November 27, 2020

Good morning gorgeous friends;
is there any equivalent of this python expression in javascript
l = [1, 2, 5, 4, 8]
n = 5
print('yeah' if n in l else 'no')

Thanks

Collapse
 
kobelobster profile image
Theo Tzaferis • Edited
console.log(l.includes(n) ? 'yeah' : 'no');
Enter fullscreen mode Exit fullscreen mode


`

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

EDIT: Never mind, the code below actually does something completely different. This is why I hate javascript ffs.

console.log(n in l ? "yeah" : "no")
Enter fullscreen mode Exit fullscreen mode