Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lodash 'includes' not working

I tried to use this function, but it's not defined (jsfiddle).

console.log(_.include([1, 2, 3], 1));
console.log(_.includes([1, 2, 3], 1));

also I saw that 'include;' without 's' work well. they have mistake in the docs? or I missed something? thanks!

like image 971
arielorvits Avatar asked Mar 06 '15 12:03

arielorvits


People also ask

What is _ get?

The _. get() function is an inbuilt function in the Underscore. js library of JavaScript which is used to get the value at the path of object. If the resolved value is undefined, the defaultValue is returned in its place. Syntax: _.get(object, path, [defaultValue])

How do I compare two arrays in Lodash?

isEqual() Method. The Lodash _. isEqual() Method performs a deep comparison between two values to determine if they are equivalent. This method supports comparing arrays, array buffers, boolean, date objects, maps, numbers, objects, regex, sets, strings, symbols, and typed arrays.

Is null or undefined Lodash?

Lodash helps in working with arrays, strings, objects, numbers, etc. The _. isNil() method is used to check if the value is null or undefined. If the value is nullish then returns true otherwise it returns false.

Is Lodash empty?

The Lodash _. isEmpty() Method Checks if the value is an empty object, collection, map, or set. Objects are considered empty if they have no own enumerable string keyed properties. Collections are considered empty if they have a 0 length.


2 Answers

You are looking at the docs for v.3.3.1 and including v.1.2.1 in your Fiddle.

_.include was renamed to _.contains, and that was later renamed to _.includes.
As of v.2.4.1, the rename to _.includes had not happened yet.

So use an updated version of lodash and all will be fine:

console.log(_.include([1, 2, 3], 1));
console.log(_.includes([1, 2, 3], 1));
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.4.0/lodash.js"></script>
like image 84
JLRishe Avatar answered Oct 05 '22 07:10

JLRishe


I'm experienced this in lodash-core 4.17.4. The solution was to use the full build instead of the core build.

like image 27
Flimm Avatar answered Oct 05 '22 06:10

Flimm