When retrieving data from a database, I have the option to include specific parts for a more targeted search.
Let's say I have an object structured like this:
{
title: "wonderland",
aliases: "",
...
}
My goal now is to generate a URL for the GET request.
getResults(obj){
return this.http.get(`${this.url}/title=${obj.title}&aliases=${obj.aliases}`)
}
In this scenario where the property 'aliases' is empty as shown above, I want to exclude the part &aliases=${obj.aliases}
. Similarly, if the 'title' property were empty, I'd want to eliminate title=${obj.title}
.
How would you go about achieving this?