I have a question similar to this question and has a slightly different problem.
So I have a function in cities.js
file
module.exports = {
newyork: function (latitude,longitude) {
console.log("newyork is here");
}
If I access this function this way if(cities.newyork){}
then true and false condition works fine but If I access function this way
var city = 'newyork';
if(cities.city){
console.log("true");
}else{
console.log(false);
}
It always goes in else condition. Because cities names would be dynamic so I need this function to work. I have tried this way as well
if(typeof cities.city === 'function'){
console.log("true");
}else{
console.log(false);
}
Still no luck. Any help would be appreciated