Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Find Data in a request

Find Data in a request


I found a code in a article as below. In this code, what does jsonrequest[define.AddStudent]) mean? Does the [define.AddStudent] resembles 'contains of' string in the variable jsonrequest? Kindly help what does line B mean?

var jsonrequest = JSON.parse(data); //Line A

if(jsonrequest[define.AddStudent]) { // Line B
    //where define.AddStudent="add student";
    console.log("Request for " + define.AddStudent);
Problem courtesy of: vinod


The jsonrequest variable is a JavaScript object.

The define variable is also a JavaScript object. AddStudent is a property / method of the define object. Let us assume that it is a string property containing "add student", as the comment tells us.

Then, the meaning of line B is: "If the property named "add student" of the jsonrequest object is defined."

Solution courtesy of: Werner Kvalem Vesterås


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Find Data in a request


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription