No specific requirement to change this code, but if you are looking for alternative way to do this, you could create a filtered array using Array.filter(predicate), then simply use Array.join(",") to create your final string.