Building a SharePoint Search URL I'm trying to build a URL to call the SharePoint Search REST API in TypeScript. The interesting part is building the querytext, which is done by my buildQueryText method. In my case it takes two parameters: A content type to search for and a array of select properties.

buildQueryText(contentType: string, selectProperties: string[]): string {
    var contentTypeQuery = "'" + "SPContentType:" + contentType + "'";

    var selectPropertiesQuery = "";
    if (selectProperties.length !== 0) {
        selectPropertiesQuery = "&amp;selectproperties=" + "'";
        selectProperties.forEach((property, index) =&gt; {
            if (index &lt; selectProperties.length - 1) {
                selectPropertiesQuery += property + ",";
            } else {
                selectPropertiesQuery += property + "'";
            }
        });
    }

    return `${contentTypeQuery}${selectPropertiesQuery}&amp;clienttype='Custom'`;
}


I'm calling the method like this: 

buildQueryText("SearchItem", ["prop1", "prop2", "prop3"])


and expecting the following output:

"'SPContentType:SearchItem'&amp;'selectproperties=prop1,prop2,prop3'&amp;clienttype='Custom'"


I'm looking for a way to improve the selectPropertyQuery part and make it more readable, as it seems quite messy. And i'm aware that there is no real validation of the inputs.
It looks to me as you want to join the array. I don't know TypeScript, it it should have a join method on the array.

selectPropertyQuery = properties.join(",")