Reputation: 31
I'm somewhat new to programming, so looking for some best practice advice. Is there a better way to write the following code, rather than using the replace() method twice?
const URL = 'user/profile/:id/result?size=:query';
const URI = URL.replace(':id', '1111').replace(':query', 100); //'user/profile/1111/result?size=100'
Upvotes: 0
Views: 130
Reputation: 2168
you can use templates by wrapping the string with back ticks (```) and using ${somevalue}
var size = 100
var id = 1111
const URL = `user/profile/${id}/result?size=${size}`
Upvotes: 1