javascript - Filtering array of objects with filter and underscore -


please check code

    var arr = [{ name:"toyota, minivan", id:"506", size: "large" }, { name:"honda moose", id:"619", size: "big" }, { name:"honda civic", id:"619", size: "mini" },{ name:"honda tree", id:"mini", size: "big" }];  var searchstr=['toyota']; var mini = _.filter(arr, function (obj) { return _.values(obj).some(function (el) {     return el.indexof(searchstr) > -1;      }); }); console.log(mini); 

the data filtering ok want if searchstr array has multiple values doesnot work how can using multiple vales in array of searchstr.something

    var searchstr = ['toyota','big']; 

you want some of search strings part of some attribute. or, if want exclusive search, use _.every, every search text appears in some attribute.

var cars = [...]  var searchinputs = ['toyota','big']; var mini = _.filter(arr, function (cars) {     return _.values(obj).some(function (carattribute) {         return _.some(searchinputs, function(searchtext){             return carattribute.indexof(searchtext) > -1;         })         }); }); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -