I have a url which takes an array of topicName query like this
localhost:3000/api/?topicName=mobile&topicName=website
and sometimes topicName only has one value like this
localhost:3000/api/?topicName=mobile
and below is how I use that query values in node JS
let topicNameArray = [];
topicNameArray = req.query.topicName
let value = topicNameArray.map(function(e) {
return new RegExp(e, "i");
})
The problem I am facing is when the array query only has one value, my app will receive this message
"message": "topicNameArray.map is not a function
Can anyone suggest me a solution to deal with this problem? Thank you so much!
console.log(topicNameArray)to checktopicNameArrayis array or string.