Hi all,
I’m trying to loop through variable names to substract corresponding columns from each other. Instead of adding a bunch of math formulas for each pair of columns i want to realize it with java snippet, because it seem more elegant and efficient. The table header looks like this:
A|B|C|…|A1|B1|C1|…
(sorry i don’t know how the formatting works here to make a table)
Since the variable names are given by java snippet (c_A, out_A etc.) i thought i could easily loop through an array i created out of the first half of the header to achieve what i want to do. I’m thinking about a forEach loop iterating through said array which builds the variables names in each iteration. Something like:
var array= v_header;
forEach (i in array) {
let a = "c_" + i;
let b = "c_" + i + "1";
let c= "out_"+i;
c=a-b;
}
(v_header is [“A”,“B”,“C”,…])
The loop itself might not work, because i’m still learning and might have to find another way, so ignore that aspect. But before i can try building a forEach loop i need to make java snippet understand that the given variables are build from strings. I tried to build the variable names without the loop and array (like var a = “c_” + “A”) which made me understand that the problem doesn’t lie in the loop but in the fact that the resulting variable isn’t congruent with the variables set by knime, but just another string.
I read about eval() which is not understood by java snippet (method is undefined) and shouldn’t be used anyway for some reason. But the alternatives (window or Function()) are also undefined or i don’t seem to grasp how to use them correctly.
I’m also not sure if all of this is a javascript related question or a knime related one, so i decided to post it here first instead of stackoverflow. Sorry if this is the wrong place.
Oh, and i’m using 4.2.5
Thanks in advance