What to use insread of Underscore.js ._where() for the arrays of property values -


let's have following data:

[  {       "name": "experiment type10",       "scale": ["whole brain", "cell"],       "datatype": "table"  },  {      "name": "experiment type11",      "scale": ["tissue", "cell"],      "datatype": "image"  },  {      "name": "experiment type12",      "scale": "tissue",      "datatype": "text"  } ] 

with underscore ._where can filter out objects datatype "text", can't filter out objects scale equals "tissue" since it's in array. possible type of filtering elegantly?

use filter , contains:

    var hastissues = function(item){         return item.scale === 'tissue' || _.contains(item.scale, 'tissue');     }      var tissues = _.filter(list, hastissues); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -