Hi , I have a question which might be more related to JS than Node Red.....
I'm trying to replace a JSON object in a Array but can't get it work. Each time the new data replaced in the array is a string, but not an object. I tried different ways, but no luck.
However, when I set the same object to a new object in the same array, then it works perfectly....
Here is a snippest of the code I use to manipulate data before sending it back into the array :
var csv = global.get("csvContent");
// When device name info provided from DB :
if (msg.topic == "DB_Device_Name" && flow.get("DeviceType") != "Not Set !") {
for (let i = 0; i < csv.length; i++) {
// Build final end point name :
var descriptorDesc = csv[i].descriptor.desc;
var descriptorLabel = csv[i].descriptor.label; //>> {desc:,label:01C01-VGW1_CH07_RxA04}
node.warn("descriptorLabel " + descriptorLabel)
descriptorLabel = msg.payload + "_CH0" + csv[i].chNumber + csv[i].rxTx + csv[i].vertexType + csv[i].audCh;
let newDesc = {"desc" : descriptorDesc}
let newLabel = {"label" : descriptorLabel}
csv[i].descriptor = Object.assign({}, newDesc, newLabel )
csv[i].test = Object.assign({}, newDesc, newLabel )
}
global.set("csvContent", csv);
When I want to replace descriptor here is the result ( I also put some screenshots, as the code section does not show any difference) :
{"desc":"","label":"12345_CH07_RxA04"}
when I set it to csv[i].test :
{"desc":"","label":"12345_CH07_RxA04"}
If useful, here is also a copy of one of the objects from csvContent source ( and dest) global variable :
{"#":"device73.484735f6-a1ea-596e-8282-0cd1108e6be2.R01a52f67-554c-5791-8503-fcbee07f93d9","active":"true","bidirPartnerId":"null","codecFormat":"Audio","configPriority":"off","control":"off","custom":"{}","descriptor":"{\"desc\":\"\",\"label\":\"12345_CH07_RxA04\"}","extraAlertFilters":"[]","Factory label":"receiver_s06_a03","isIgmpSource":"false","mainDstIp":"null","mainDstMac":"null","mainDstPort":"null","mainDstVlan":"null","mainSrcGateway":"null","mainSrcIp":"null","mainSrcMac":"null","mainSrcNetmask":"null","public":"false","sdpSupport":"true","sipsMode":"NONE","spareDstIp":"null","spareDstMac":"null","spareDstPort":"null","spareDstVlan":"null","spareSrcGateway":"null","spareSrcIp":"null","spareSrcMac":"null","spareSrcNetmask":"null","tags":"[]","useAsEndpoint":"false","chNumber":7,"vertexType":"A","rxTx":"_Rx","audCh":"04","test":{"desc":"","label":"12345_CH07_RxA04"}}
Thanks to you in advance for your tips !