Web socket! Combine functions for ws.textAll

This way I transmit the remaining time before the timers are turned on.

void remaining_time() {
if (criterion-1) {
    ws.textAll("buffer1=" + String(buffer1));
  }

if (criterion-2) {
    ws.textAll("buffer2=" + String(buffer2));
  } 
 
if (criterion-3) {
    ws.textAll("buffer3=" + String(buffer3));  
  }
}

In JavaScript:

function onMessage(event) {	
var arrayS = event.data.split("=");	
switch (arrayS[0]) {		
case 'buffer1': document.getElementById("time1").innerHTML = arrayS[1]; break		
case 'buffer2': document.getElementById("time2").innerHTML = arrayS[1]; break		
case 'buffer3': document.getElementById("time3").innerHTML = arrayS[1]; break	
 }
}

Everything works well. But I need to add in addition to this, the function of transmitting the state of the buttons.
I see it this way.

void button_status() {
if (criterion_butt-1) {
    ws.textAll(String(!ledState1));
  }

if (criterion_butt-2) {
    ws.textAll(String(!ledState2 + 2));
  } 
 
if (criterion_butt-3) {
   ws.textAll(String(!ledState3 + 4)); 
  }
}

JavaScript:

function onMessage(event) {
	switch (event.data) {
		case '0': document.getElementById("state1").innerHTML = "OFF"; break
		case '1': document.getElementById("state1").innerHTML = "ON";break
		case '2': document.getElementById("state2").innerHTML = "OFF"; break
		case '3': document.getElementById("state2").innerHTML = "ON"; break
		case '4': document.getElementById("state3").innerHTML = "OFF"; break
		case '5': document.getElementById("state3").innerHTML = "ON"; break
		}
	}

But I don't understand how to combine these two functions correctly. Ie, the main problem
in JavaScript is to somehow distinguish (separate) them from each other.
Could you help me with this issue? If this was an example with comments for understanding, that would be excellent.

How about using the variable name for differentiating between the two cases?

So in addition to buffer1, buffer2 and buffer3 you may have buttonState which then can have values '0' to '5'.