Manage an object dynamically

Hi, let's consider to have 8 messages to output from a function, they are all initally set with payload:false
Now I want that one of 8, depending on the msg.topic input is turning to null, how to?

let msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8;
msg1 = msg2 = msg3 = msg4 = msg5 = msg6 = msg7 = msg8 = { payload: false };
let index=msg.topic;
msg[index]=null;
return [msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8];

Thi is acceptable but return NodeJS under windows to go high CPU and NR freezing, then I need to kill it

If msg.topic is an integer, use a single message which has an array:
let myarray = [false, false, false, false ...]
myarray[msg.topic] = null
msg.payload = myarray
return msg

Or if it's a string, an object
let myobject = {"topic1": false, "topic2": false, ... }
myobject[msg.topic] = null
msg.payload = myobject
return msg

let output = [{ payload: false },{ payload: false },{ payload: false },{ payload: false },{ payload: false }{ payload: false },{ payload: false }];
let index = msg.topic;
output[index] = null;
return output;

something like this is cleaner
You may want to check topic is a number between 0 and 7 also, before setting output[index]