javascript - Filter Records from JSON with Node or ES6 -
i'm not sure best way go this. want iterate json
, find companies in example. json
might way more complex app grows too, in levels, objects, etc. want know ways people doing simple searching filtering out subsets of data json
, node.js
and/or es6
or libraries maybe such lodash
, etc.
so example json, ways can search , pull companies in usa?
[{ "id": 0, "name": "company1", "logourl": "/lib/assets/company1-logo.png", "location":{ "country": "usa", "state": "california", "city": "napa" }, "active": false }, { "id": 1, "name": "company2", "logourl": "/lib/assets/company2-logo.png", "location":{ "country": "germany", "state": "", "city": "berlin" }, "active": false }, { "id": 2, "name": "company3", "logourl": "/lib/assets/company3-logo.png", "location":{ "country": "usa", "state": "michigan", "city": "detroit" }, "active": false }]
use javascript native array#filter
method es6 arrow function
var res = data.filter(v => v.location.country === 'usa');
var data = [{ "id": 0, "name": "company1", "logourl": "/lib/assets/company1-logo.png", "location": { "country": "usa", "state": "california", "city": "napa" }, "active": false }, { "id": 1, "name": "company2", "logourl": "/lib/assets/company2-logo.png", "location": { "country": "germany", "state": "", "city": "berlin" }, "active": false }, { "id": 2, "name": "company3", "logourl": "/lib/assets/company3-logo.png", "location": { "country": "usa", "state": "michigan", "city": "detroit" }, "active": false }]; var res = data.filter(v => v.location.country === 'usa'); console.log(res);
Comments
Post a Comment