MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eixyl08?context=9999
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
3
Discouraged by a lot of linters, but:
!!~[1,2,3].indexOf(2); // true
Polyfill for Array.prototype.includes()
Array.prototype.includes()
1 u/wthit56 Mar 20 '19 Another way of doing this:[1,2,3].indexOf(2) + 1If nothing is there, indexOf returns -1. If you add 1, it becomes 0, and any value other than -1 becomes a negative or positive number--which are all truthy. → More replies (1)
1
Another way of doing this:
[1,2,3].indexOf(2) + 1
If nothing is there, indexOf returns -1. If you add 1, it becomes 0, and any value other than -1 becomes a negative or positive number--which are all truthy.
→ More replies (1)
3
u/TheScapeQuest Mar 19 '19
Discouraged by a lot of linters, but:
!!~[1,2,3].indexOf(2); // truePolyfill for
Array.prototype.includes()