Q:

How to check if key exists in the data from the server in javascript?

I get some JSON values from the server but I don't know if there will be a particular field or not.
Sometimes i get the response in this form
{
 "regatta_name":"ProbaRegatta",
  "country":"Congo",
  "status":"invited"
}

Where as sometimes i get reponse in this form 
{
 "regatta_name":"ProbaRegatta",
  "country":"Congo",
  "status":"invited",
   "vehicle": "yes"
}

How to check if vehicle key exists in the javascript object.?

A:

Since you don't know if the object will be there or not then you can check with the response['prop'] syntax. You can also check with the dot syntax, as is being done above, but I prefer this way. I got into this habit because the response.prop syntax won't work in Typescript unless the property is clearly known by the compiler.
if (serverResponse && serverResponse['vehicle']) {
    // vehicle key exists
    // do your stuff 
} else {
    // vehicle key Does Not exist
    // do your stuff 
}

A:

There are multiple ways to do the check like:
const obj = {
   "regatta_name":"ProbaRegatta",
   "country":"Congo",
   "status":"invited",
   "vehicle": "yes"
};

by using in operator: if("vehicle" in obj){ -- }
by using hasOwnProperty:  if(obj.hasOwnProperty("vehicle")){ -- }
by checking: if(obj["vehicle"]){ -- } or if(obj.vehicle){ -- }

