I create a simple search that searches for an array of objects that starts with a string passed from input.
So, I have this:
var items = [ {id: 1, tags: ['foo']}, {id: 2, tags: ['fish', 'ball']}, {id: 3, tags: ['bar', 'goo']}, ]; input.on(function(e) { var test = _.filter(items, function(item) { return _.includes(_.pluck(items, 'tags'), input.val()); }); console.log(test); });
This always returns an empty array, I think I am missing startsWith how to use it here in my implementation:
The expected result should be:
input: 'f' output: [{id: 1, tags: ['foo']}, {id: 2, tags: ['fish', 'ball']}]
since the two elements have tags starting with f
source share