Split the string into separate values

hello everyone
i m very much confused how to split the string into saparate values .
as i have 4 values in a string

  1. temperature
    2.humidity
    3.pir
  2. ldr
    but the values are in the form of string and i want to saparate it into
    temperature
    humidity
    pir
    ldr
    how can i do it .
    plzz help

In the last screenshot you posted the debug panel shows every message as a string of comma separated values, NOT an array.

So do you want to convert an array or split the string into separate values?

You also posted this in a category for creating nodes, for general how-to question in existing nodes please use a more appropriate category.
Hopefully on of the super-users can move it…

split the string into separate values

If you want them as separate messages take a look at the split node

i have used some codes
can u tell me that these codes will work for me or not??

Values in your string are comma separated. So splitting has to be done with separator comma.
var output = msg.payload.split(",");

1 Like

still i am not getting what i wanted
the string had not changed to saparate values as:
temperature
humidity
pir
ldr

First element of array has index 0 (zero)
You probably get an error now as you are looking last element from index 4, but it appears to be out of range.


this is the error what i m facing
can u give me the complete code i am a bit confused in my code

You are returning the numbers [temp,humidity.....]
You should return those objects you a created [msg1,msg2, ....]

having created the msgs you need to return them not temp etc
so

return [ msg1, msg2, msg3, msg4 ];


but i want
temperature
humidity
pir
ldr
to be displayed saparately. not in a string

[quote="Srijan, post:12, topic:2818"]
but i want
temperature
humidity
pir
ldr
to be displayed saparately. not in a string

where are your debug nodes attached ? - looks like you are only showing us the one on the input - not 4 on the outputs of your function...

Is your debug is still attached to your MQTT node?

Take a look at the outputs from your function node.

yes my debug is still attach to mqtt node

i am new to node red
plzz help me

So your debug will only ever show the MQTT message. You need to look at the outputs of your function node.

okk i am looking