Ok, My inexperience with Javascript is showing!

If have a payload that has the following:

array[1]
0: object
Index: 1

How the heck do I get to the value of the index key? This is a javascript array, with one element, that happens to be a javascript object? Or I am misunderstanding this?

If someone bumps me to nodejs forum... ok. :slight_smile:

msg.payload[0].Index?

Swear I have tried that... All I get is undefined.

Debug...

6/30/2020, 10:09:04 AMnode: QueryINSERT INTO Ambient(`Time`, `Altitude`, `Sensor`, `Temperature`, `Pressure`, `Humidity`, `Host`) VALUES (1593466209.1504729, null, 0, 32.10307469291219, null, 29.829861905851836, 0); : msg.payload : string[75]
"1593466209.1504729, null, 0, 32.10307469291219, null, 29.829861905851836, 0"
6/30/2020, 10:09:04 AMnode: RawINSERT INTO Ambient(`Time`, `Altitude`, `Sensor`, `Temperature`, `Pressure`, `Humidity`, `Host`) VALUES (1593466209.1504729, null, 0, 32.10307469291219, null, 29.829861905851836, 0); : msg.payload : Object
{ fieldCount: 0, affectedRows: 1, insertId: 25, serverStatus: 2, warningCount: 0 … }
6/30/2020, 10:09:04 AMnode: Insert Ambient DataINSERT INTO Ambient(`Time`, `Altitude`, `Sensor`, `Temperature`, `Pressure`, `Humidity`, `Host`) VALUES (1593466209.1504729, null, 0, 32.10307469291219, null, 29.829861905851836, 0); : msg : undefined
undefined

Hi. You can save yourself a lot of trouble if you use the copy path button that appears when you hover over a debug output.

You learn this and much more from this Playlist: Node-RED Essentials. It is by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in less than an hour.

Ah, Thanks!

Or, if you're more for the reading documentation based approach, this document from the Node-RED docs is worth a read: Working with Messages

1 Like

I have watched some, read most. One of the reasons I have gone from zero to now, never having worked with Node Red before about 2 weeks ago, or touched Javascript... many other languages just not js based stuff. But I digress... I figured out why it was not working, my SQL statement was NOT returning Index field query correctly... jeez. Such a rookie mistake.

1 Like

Curious... there is a flow.keys() function but no flow.values() function? That seems a bit odd.

flow.keys gives you the keys, which you can use to get the values. A javascript object does not have a method to get just the values as far as I know. The values would be meaningless without the associated keys as you wouldn't know which was which.

1 Like

You'll likely find the reason from this feature request I wrote (spoiler - it didn't get support): Support destructuring expression for context properties

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