1
votes

Im JS novice, My problem is that i have a var resortuid its value is from PHP (its working) i need to open a json file with resortuid in link. In other words i need ro replace XXXX in url with resortuid var. I`m sure that it is banal question, byt not for me

  var resortuid = '1125';
      var settings = {  
        "url": "https://aaa.aa/XXXX_simple.json",
        "method": "GET",
        "timeout": 0,
      };
1
You can simply concatenate the strings, are you asking for the most efficient way?Sinan Yaman

1 Answers

2
votes

You can use JavaScript Template literals:

const resortuid = '1125';
const settings = {  
  "url": `https://aaa.aa/${resortuid}_simple.json`,
  "method": "GET",
  "timeout": 0,
};
      
console.log(settings.url)

By the way, Var, Let, and Const – What's the Difference? might be worth reading.