Output variables to javascript file

i am a newbie in arduino programming... Could you help me to shrink the code which aim to output a lot of variables to javascript file. :blush:

static word settingsJS() {
  
  bfill = ether.tcpOffset();                       
  bfill.emit_p(
  PSTR(                                
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: application/x-javascript\r\n"
    "Pragma: no-cache\r\n"
    "\r\n"
   "rlnum = $D; st=[$D,$D,$D,$D,$D,$D];"
   "al={"
     "0:{start:{h:$D,m:$D},end:{h:$D,m:$D}},1:{start:{h:$D,m:$D},end:{h:$D,m:$D}},"
    "2:{start:{h:$D,m:$D},end:{h:$D,m:$D}},3:{start:{h:$D,m:$D},end:{h:$D,m:$D}},"
    "4:{start:{h:$D,m:$D},end:{h:$D,m:$D}},5:{start:{h:$D,m:$D},end:{h:$D,m:$D}}};"
    "tm={0:{on:$D,off:$D},1:{on:$D,off:$D},2:{on:$D,off:$D},3:{on:$D,off:$D},4:{on:$D,off:$D},5:{on:$D,off:$D}};"
   "tm2={0:{on:$D,off:$D},1:{on:$D,off:$D},2:{on:$D,off:$D},3:{on:$D,off:$D},4:{on:$D,off:$D},5:{on:$D,off:$D}};"
   "a=[$D,$D,$D,$D,$D,$D];"
   "t1=[$D,$D,$D,$D,$D,$D];"
   "t2=[$D,$D,$D,$D,$D,$D];"
   "time=$D;"
     ),
       NUMBER_OF_RELAYS, relayState[0], relayState[1], relayState[2], relayState[3], relayState[4], relayState[5],
       hour(alarmsSettings[0][0]),minute(alarmsSettings[0][0]),
       hour(alarmsSettings[0][1]),minute(alarmsSettings[0][1]),
       hour(alarmsSettings[1][0]),minute(alarmsSettings[1][0]),
       hour(alarmsSettings[1][1]),minute(alarmsSettings[1][1]),
       hour(alarmsSettings[2][0]),minute(alarmsSettings[2][0]),
       hour(alarmsSettings[2][1]),minute(alarmsSettings[2][1]),
       hour(alarmsSettings[3][0]),minute(alarmsSettings[3][0]),
       hour(alarmsSettings[3][1]),minute(alarmsSettings[3][1]),
       hour(alarmsSettings[4][0]),minute(alarmsSettings[4][0]),
       hour(alarmsSettings[4][1]),minute(alarmsSettings[4][1]),
       hour(alarmsSettings[5][0]),minute(alarmsSettings[5][0]),
       hour(alarmsSettings[5][1]),minute(alarmsSettings[5][1]),
       timerSettings[0][0][0],timerSettings[0][0][1],
       timerSettings[1][0][0],timerSettings[1][0][1],
       timerSettings[2][0][0],timerSettings[2][0][1],
       timerSettings[3][0][0],timerSettings[3][0][1],
       timerSettings[4][0][0],timerSettings[4][0][1],
       timerSettings[5][0][0],timerSettings[5][0][1],
       timerSettings[0][1][0],timerSettings[0][1][1],
       timerSettings[1][1][0],timerSettings[1][1][1],
       timerSettings[2][1][0],timerSettings[2][1][1],
       timerSettings[3][1][0],timerSettings[3][1][1],
       timerSettings[4][1][0],timerSettings[4][1][1],
       timerSettings[5][1][0],timerSettings[5][1][1],
       alarmState[0],alarmState[1],alarmState[2],alarmState[3],alarmState[4],alarmState[5],
       timerState[0][0],timerState[0][1],timerState[0][2],timerState[0][3],timerState[0][4],timerState[0][5],
       timerState[1][0],timerState[1][1],timerState[1][2],timerState[1][3],timerState[1][4],timerState[1][5],
       now()
       );             
  return bfill.position();                                         
}

 ether.httpServerReply(settingsJS());

Could you help me to shrink the code which aim to output a lot of variables

You seem to be operating under the mistaken impression that it can be shrunk.

To start with I would split it up into sections and build each array on it's own. Once you split them up you will start to see how you can loop through each section.

For example the relay state array might be made like this:

String st = "st=[";
for (int i = 0; i < NUMBER_OF_RELAYS) {
    st = st + relayState[i] + ",";
}
st = st + "];";

Then at the end, once you've created all the sections, you would concatenate all the sections and pass them to the function.

You might want to think about sending the data in JSON, it won't make much difference , but it is the more correct way of doing this. Maybe you could use something like this: GitHub - interactive-matter/aJson: aJson is an Arduino library to enable JSON processing with Arduino. It easily enables you to decode, create, manipulate and encode JSON directly from and to data structures.

Yes! JSON is the best way! I did not know that such library exists! Thanks!

:~ Unfortunately this library does not support Arduino Nano...

This one looks better: GitHub - bblanchon/ArduinoJson: 📟 JSON library for Arduino and embedded C++. Simple and efficient.
There seem to be a few of them if you google it.