Querying JSON with JS (using unknown parent)

0 votes
asked Apr 22, 2013 by milk-man

Lets says we have an object that looks like this.

 // first name - of employee 3 company.employees.employeeId[3].first // last name - of employee 3 company.employees.employeeId[3].last // department - of employee 3 company.employees.employeeId[3].department

is there a way/library to do a query like this

 // looking for all employees in department Z result = company.employees.[*].department['accounting']

1 Answer

+3 votes
answered Nov 29, 2018 by blender

You could .filter() them:

var result = company.employees.employeeID.filter(function(employee) { return employee.department === 'accounting';
});
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...