arrays - Vanilla Javascript equivalent for lodash _.includes -


i'm using lodash includes function check if target value exists in array...

_.includes(array, target)  

and hoping find equivalent in es5 (or es6)

did miss something? there no es5 array.prototype equivalent?

or option use indexof?

es7: array.prototype.includes()

[1, 2, 3].includes(2);     // true 

es5: array.prototype.indexof()>= 0

[2, 5, 9].indexof(5) >= 0;   // true [2, 5, 9].indexof(7) >= 0;   // false 

if prefer function:

function includes (array, element) { return array.indexof(element) >= 0 } 

and use as:

includes([2, 5, 9], 5);    // true 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -