I had written a Gruntfile, which makes heavy use of Array.prototype.includes() and similar functions. I have discovered I need to downgrade the version of node to version 4.4.5. Once I do this, I no long am able to use statements such as if ( myarray.includes(somevalue) ), and it will fail saying: >> TypeError: myarray.includes is not a function. When I look at the node documentation, it seems to be for the current version of node, so I'm not sure what's the alternative.
What is the equivalent of an array 'includes', in versions of node 4 and below? Also, are there other huge differences I'd need to be aware of? (Another I have found is no support for default params in a function declaration).
You can always just polyfill includes so that you can continue to use it. There's even an "official" polyfill here.
Anyway, barring that, the equivalent would be the indexOf method, which returns -1 if the item isn't found, or its index otherwise. So
array.includes(item);
can be replaced by
array.indexOf(item) !== -1;
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