I’m trying to append a value only if a condition is met (distance != “off”).
This is what I tried but I cannot get it to work?
var params = {
q: pizza,
result_type: "mixed",
include_entities: "true",
if(distance != "off") {
geocode: geolocation,
}
rpp: 15,
page: 1
};
How can it be done?
Tou have two options with different implications.
Option 1:
or Option 2:
Option 1 would mean geocode is defined and you’d need to check for null or whatever you decide the default value should be. Option 2 would mean that geocode is undefined, which is what you suggest you would like to do with your original code example.