How to convert all the items in a String array to Numbers?

Hello! I am trying to convert an array that contains string values to Numbers, so the array contains something like

array = [0: "5", 1:"15", 2:"0", 3:"30"]

This array is also a value coming from a transformer, so transformer1.value returns the array above. Now, I need to convert all the values inside the array to numbers so I can do math operations with them

So far I tried a loop like this

var data = {{ transformer1.value }} //this is the transformer that contains the array
var Minutes = [] // an empty array
var i = 0
Minutes[i] = {{ parseInt(data[i]) }}

when I do the loop above, I get an error saying that 'i' is not defined but it is defined inside the loop, do you know what am I doing wrong or how can I accomplish to loop through the entire array to covert all values to numbers?

That's interesting; when I replicate the issue, it seems to work fine for me.

The Loop:

The Result:


Of course I'm sure your transformer1 is much more complicated, it should be returning that value.

1 Like

Hello there!

Great question! Would you want to do this all within the transformer?

If not, you can do something like this as an additional transformer.

If this doesn't work for you, do you think you could share a screenshot of your bottom panel with this transformer that is erroring out?

Hello jSims, yes I wanted to do it all within the same transformer if possible, I tested this and it worked smoothly, thank you very much!

My pleasure! Happy to help! :smile: