Array path identifier wild card

I have array that I am trying to read values from the problem is part of the path changes in my case it is a mac address. Normal path like say from a mysql return would be msg.payload[0].TalkID but in my case it is payload["be:10:3d:xx:xx:xx"].wds. How can I select the wds field when the path could be difficult with every message.


Maybe something like this could be a good starting point?

var keyMatch = function(o,r){

    var c  = 0;
    var nO = {};

        no[k] = k.match(r) ? o[k] : void 0;

    return ( ~c ? JSON.stringify(JSON.parse(nO)) : null );

var test = {
    '00:02:02:34:72:a5': 'abc' ,
    'Hello world': 'acb',
    '00:02:02:34:72:a3': 'def'


you could use object.keys() to find the property name.

msg.payload = msg.payload[Object.keys(msg.payload)[0]].wds
return msg
1 Like

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