Function to replace a word with payload

Hey, hope i am using this forum like it used to be.
At first english is not my first language :wink:

I am new to node red and programming.
I want to replace a word in a msg.payload with coordinates i get from an array.

msg.payload = "";
var url = msg.payload.replace("laenge",msg.payload[0]).replace("breite",msg.payload[1]);
msg.payload = url
return msg;

so that he sends the url to a http request but with the coordinates.

If u need more information or something let me know! I didnt find a solution for this problem and with my bad knowledge about programming i am done and need 2 ask for help.

greetz paco

msg.payload.replace() is a string function, but msg.payload[0] is an array. They both can not exist at same time. msg.payload is either a string or an array.

is there a way i can make it possible otherwise?

sure use a different variable name for the msg.payload

let url = "";
url = url.replace("laenge",msg.payload[0]).replace("breite",msg.payload[1]);
msg.payload = url;
return msg;

you are awesome! have a nice day!

is it possible to explain me what "let" does? or give me an link where i can learn this.
Just Copy Past is ok for now but not for the future :slight_smile:

similar to Var but scope is is different.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.