I have one correction for you.
if(array.indexOf(4) >= -1 )
Needs to be:
if(array.indexOf(4) > -1 )
In order to check, whether an element is in the array. Otherwise the condition would always be true.
Yeah. indexOf() always return -1 if element is not found. Thanks Jonas
You forgot to mention one of the main differences between includes() and indexOf().
IE does not support includes() whereas it supports the other.
I think IE11 started supporting Array.prototype.includes. Exact version that I'm using is 11.904.16299.0
Yeah. Very true.
Uhm in all honesty isn't +0 exactly the same as -0? So is there any real life need to distinguish between +0 and -0?
includes looks interesting, thank you for your post.
I'm glad this helped!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.