Been at this for a few hours and have plumbed the depths of these forums, but I am still stuck.....
Doing a select on a MySQL database and if some of the results are missing from the database, I get a TypeError undefined.... so I need to check for it and simply replace the missing bits of data with something else (in my case "" will do).
Here are the tests I have used to try and detect the 'undefined' case;
Am I understanding correctly that you're looking at a situation where you have an object, and you're hoping to test whether the object has a certain key?
If so, have you tried for msg.payload.hasOwnProperty('type')?
I missed a [0] in your screenshot. What it does is it checks with the object you call it on (in my example above on msg.payload) for the existence of a property (or a key, if you will) named 'type'. So instead, try it with msg.payload[0].hasOwnProperty('type')
If it still isn't working feed the message you are trying to test into a debug node and show us what the message contains. I don't think you have done that so far, or if you did I did not understand what you were showing.
OK, the payload is an empty array. So in your function you can use something like if (msg.payload.length > 0) {
Whenever you have a node which is not doing what you expect the first thing to do is to check what is going into it so you know what you are dealing with.
Slight correction, you have tested for msg.payload.type.length to be 0. Not for the length of msg.payload. Testing for type.length would have for the number of characters, or if it was an array for the number of elements in the array, for msg.payload.type.
Please post the full function, with the msg.payload.length test so we can see what else is going on in the function. Copy the source please, go to a new line and click the </> button and paste it in there.
Sometimes correct.
Some aircraft have types and descriptions and some have different combinations.
Since I never get to test for descriptions, I have not worried about that check yet... Once I get the missing 'type' I can work on any missing 'descriptions'.
This line will cause a string concatenation to happen, it will take msg.payload and get the toString() version of it and adds it to the string "Raw ". If instead you were to use it for debugging, try warning directly with msg.payload. When you see Raw [object object] in the debug sidebar, it's because msg.payload is an object, and toString of an object results in the string representation of [Object object].
Furthermore, this line ICAO: msg.aes = "https://tar1090.adsbexchange.com/?icao="+ msg.aes, will likely not do what you think it will.