angularjs - Searching in a JSON object with generated query string -


i trying search json object in angular js using lo-dash. challenge here json structure change dynamically. result, search query string have change.

my json of format :

    {                    "series": "abc000123123",             "sector": "e",             "industry": "n31",             "duration": "1a"    },      {        "series": "abc000123456",             "sector": "e",             "industry": "n11",             "duration": "12"    },      {        "series": "abc000456789",             "sector": "e",             "industry": "n31",             "duration": "1b"    } 

my json can of following format:

{                    "series": "def000321",             "area": "c2",             "item": "123"    }, {                    "series": "def000321",             "area": "d0",             "item": "675"    }, 

the keys area, item, sector, industry, etc vary.

in above cases, series field remains constant. need pass in key, value pairs of rest of attributes retrieve series value.

for simplicity sake, approach using lodash in searching above json follows:

_.map(_.filter(json_object, function (value) {  return (value.area == d0) && (value.item == c2) }), 'series'); 

where generating following string programmatically :

(value.area == 'd0') && (value.item == 'c2')

this approach not work. when hard code values, works fine. doesn't other way round when programmatically generate query string.

i tried iterating on list , filtering out 1 attribute @ time increase loop count , complexity of search.

any suggestions/ work around ? in advance

edit: added screenshot of console : enter image description here

try approach: https://fiddle.jshell.net/koljada/53esaqlz/1/

var json_object = [{   "series": "abc000123123",   "sector": "e",   "industry": "n31",   "duration": "1a" }, {   "series": "abc000123456",   "sector": "e",   "industry": "n11",   "duration": "12" }, {   "series": "abc000456789",   "sector": "e",   "industry": "n31",   "duration": "1b" }];  var query = "(value.sector == 'e') && (value.industry == 'n11')";  var result = _(json_object)   .filter(new function("value", "return " + query))   .map('series')   .value(); // => ["abc000123456"]