I have this issue with a JS function array.includes. I have this array:
The thing is when I use this code, nothing will happen.
var array_type;
//array has these 2 values:
//array_type[0] == 0;
//array_type[1] == 2;
if (array_type.includes(2)) {
console.log("good");
}
Do you have any idea why? Thank you for any help.
If you are using Internet Explorer then array.includes() will not work. Instead you need to use indexOf. Internet Explorer doesn't have a support for Array.includes()
var array_type = [0, 2];
if (array_type.indexOf(2) !== -1) {
console.log("good");
}
References for includes()
References for indexOf()
Check the browser compatibility sections in the link
This code works
[1,2].includes(2)
but you have to be careful if you can use the includes function
https://caniuse.com/#search=includes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With