How to extract a property from an object containing "/"

Hi mates, I would use a node that works good, but unfortunately the author decided to output an object which I can't easly address in NR, this is the picture:

I can't type in a function: var ADC0 = msg.payload./dev/i2c-1.ads1115.0x4A.singleEnded.channel_0.miliVolts;
How can I get that value? Thank you

This should work
let ADC0 = msg.payload["/dev/i2c-1"].ads1115["0x4A"].singleEnded.channel_0.miliVolts;

Though I note that it is 0x48 in the debug.
The node red docs page Working with Messages shows you how you can easily copy the path to a property from the debug pane, so avoiding this sort of problem.

Thank you, didn't know, I'll remember about it! :slight_smile:
Why you used let instead of var?

It is a matter of scoping. In this case it won't make any difference, but nowadays there is no reason to ever use var as far as I am aware. One should use the more modern let or const. If you only set the value of the variable once then it should be const.

var was introduced, I believe, when javascript was a very simple language and nobody bothered about scoping. Nowadays it is better to scope a variable to the area it is used in order to prevent accidental overwriting by another piece of code.

2 Likes

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