var includes =require('array-includes');var assert =require('assert');var arr = [ 'one','two' ];includes(arr,'one'); // trueincludes(arr,'three'); // falseincludes(arr,'one',1); // false
Example
var arr = [1,'foo',NaN,-0];assert.equal(arr.indexOf(0) >-1,true);assert.equal(arr.indexOf(-0) >-1,true);assert.equal(includes(arr,0),true);assert.equal(includes(arr,-0),true);assert.equal(arr.indexOf(NaN) >-1,false);assert.equal(includes(arr,NaN),true);assert.equal(includes(arr,'foo',0),true);assert.equal(includes(arr,'foo',1),true);assert.equal(includes(arr,'foo',2),false);
/* when Array#includes is not present */deleteArray.prototype.includes;var shimmedIncludes =includes.shim();assert.equal(shimmedIncludes,includes.getPolyfill());assert.equal(arr.includes('foo',1),includes(arr,'foo',1));
/* when Array#includes is present */var shimmedIncludes =includes.shim();assert.equal(shimmedIncludes,Array.prototype.includes);assert.equal(arr.includes(1,'foo'),includes(arr,1,'foo'));
Tests
Simply clone the repo, npm install, and run npm test