I'm trying to create an array of a certain length filled with 0. I used this code to do it:
// Create the "conditionMet" object to determine if the recipes conditions have been met by the triggers
msg.conditionMet = new Array(msg.myRecipes.length).fill(0)
The array seems to initialize correctly as seen through the debug node:
Then when I try to modify the values through a switch statement (part of it here):
for (i = 0; i < msg.myRecipes.length; i++){
// Gets the current trigger condition to pass in the switch statement
//var triggerCondition = msg.triggerConditionArr[i];
var triggerCondition = msg.myRecipes.r_Trigger[i];
switch(msg.triggerCondition){
// Half Ranges
case "percentage-S-50":
if (potentiometerVal <= 50){
msg.conditionMet[i] = 1;
}
break;
case "percentage-G-51":
if (potentiometerVal >= 51){
msg.conditionMet[i] = 1;
}
break;
// Increments of 10 ranges
case "percentage-B-0-9":
if (potentiometerVal >= 0 && potentiometerVal <= 9){
msg.conditionMet[i] = 1;
}
break;
(.... switch statement continues here)
That code is correct, so the issue will be somewhere else in your flow.
The first debug screenshot you have shared is showing is msg.triggerConfitionArr - which is a different property to the one in the initial code - msg.conditionMet. So that doesn't tell us anything about the original array.
In your bigger piece of code, you configure the for loop to iteration from 0 to msg.myReceipes.length. But in the next line you access msg.myRecipes.r_trigger[i].
Without knowing the structure of your message, I can't say what it should be - but I can tell you what you have currently is wrong.
In which case, I think you need to change the opening lines of the loop as follows (I've made it more verbose than it needs to be, but hopefully that helps make it clearer)
for (i = 0; i < msg.myRecipes.length; i++){
// Get the recipe
var recipe = msg.myRecipes[i];
// Get the r_trigger for this recipe
var triggerCondition = recipe.r_Trigger;
// Use that value in the switch:
switch(triggerCondition){