Split the string into separate values

#1

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
0 Likes

#2

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…

0 Likes

#3

split the string into separate values

0 Likes

#4

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

0 Likes

#5

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

0 Likes

#6

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

0 Likes

#7

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

0 Likes

#8

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.

0 Likes

#9


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

0 Likes

#10

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

0 Likes

#11

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

return [ msg1, msg2, msg3, msg4 ];
0 Likes

#12


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

0 Likes

#13

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

0 Likes

#14

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...

0 Likes

#15

Is your debug is still attached to your MQTT node?

Take a look at the outputs from your function node.

0 Likes

#16

0 Likes

#17

yes my debug is still attach to mqtt node

0 Likes

#18

i am new to node red
plzz help me

0 Likes

#19

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

0 Likes

#20

okk i am looking

0 Likes