maximus26
maximus26

Reputation: 65

add const to a string?

I just startet learning React Native an got a problem.

i fetch a php file from my server and need to add a ID parameter to the url. the ID parameter is saved in a const.

How can I add my const to the end of the fetch url?

const Round = 1;

return fetch('http://myurl/data.php?ID=')

Upvotes: 0

Views: 3816

Answers (3)

Ahsan Ali
Ahsan Ali

Reputation: 5135

All you need is to concatenate the Round variable.

const Round = 1;
return fetch('http://myurl/data.php?ID='+Round);

You may also use Template literals

return fetch(`http://myurl/data.php?ID=${Round}`);

Upvotes: 2

Colin Ricardo
Colin Ricardo

Reputation: 17269

Use template literals:

const round = 1;
return fetch(`http://myurl/data.php?ID=${round}`);

Note: regular variables should have lowercase names, by convention.

Upvotes: 1

Jitender Badoni
Jitender Badoni

Reputation: 212

Just put const variable at the end

For Example :

const Round = 1;

return fetch('http://myurl/data.php?ID='+Round)

Upvotes: 0

Related Questions