how can i read query.students.queryType?
query = {"students":[{"searchField":"lastname","queryType":"exact","query":{"text":"jack"}}]}
CodePudding user response:
JSON.parse(query) @mahooresorkh thanks it did worked
CodePudding user response:
Access it like this:
query.students[0].queryType
CodePudding user response:
Probably the problem is because of, query type is string (stringified json), and you are trying to get students property of a string type. So it is undefined.
First convert the stringified json to a json object using:
const jsonObj = JSON.parse(query);
Then get the value of students members using forEach:
jsonObj.students.forEach(student => {
console.log(student.queryType)
// you can get the value of queryType for each student
});
