0

I am trying to use a variable inside of a string, I am using code to send a PDF copy of the spreadsheet, my goal is to set a custom size for the PDF page. Here is the current code I am using;

const exportOptions =
'exportFormat=pdf&format=pdf' + // export as pdf / csv / xls / xlsx
'&size=5x5' + // A = Width / B = Height

I want to change the size variable to look like this;

'&size=(Variable A) x (Variable B)' + 

I have no clue how to insert a variable in to the string. Any help would be very apricated :)

Sondre
  • 7
  • 2

1 Answers1

1

Java script has a very simple way to include variables in side strings

Option 1

var width = 5;
var height = 5;

var string = "&size=" + width + " x " + height;

console.log(string);

Option 2

var width = 5;
var height = 5;

var string = `&size=${width} x ${height}`;

console.log(string);
Ryan
  • 69
  • 4