I would like to use the lodash method _.includesin my code, but at any time I have an array of objects, I can not get it to work, but instead rely on the method _.find.
From my tests, I can only get _.includesto work with just arrays. But maybe this is how it should work?
I am very new to Lodash and programming in general, so I thought I would ask if I am missing something, how can I use this method.
I created jsbin with the following code: http://jsbin.com/regojupiro/2/
var myArray = [];
function createArray(attName, attId, otherId) {
var theObject = {};
theObject.attributeName = attName;
theObject.attributeId = attId;
theObject.otherId = [otherId];
return theObject;
}
myArray.push(createArray('first', 1001, 301));
myArray.push(createArray('second', 1002, 302));
myArray.push(createArray('third', 1003, 303));
myArray.push(createArray('fourth', 1004, 304));
var isPresent1 = _.includes(myArray, {'attribtueId' : 1001});
var isPresent2 = _.includes(myArray, 1001);
var found = _.find(myArray, {'attributeId' : 1001});
console.log(isPresent1);
console.log(isPresent2);
console.log(found);
console.log(myArray);
Both isPresent variables return false, but the method _.findreturns the correct object.
, _.includes, true/false, , .
, , _.find - lodash, ?
!