@AxelD posted a new topic, subject "Help array: need to put an array in an array". It read:

   Hey guys!
    
    I need some help. In the first payload there is an array of data and I want to write a function that puts that array one step further.
    
    Now it is msg.payload[ ] ==> I want it to be msg.payload.metadata[ ]
    
    Can you help me?
    
    Thanks!
    
    afbeelding752×213 9.52 KB
    
      
    
    
    afbeelding291×675 7.27 KB

After which, @Steve-Mcl (Stephen McLaughlin) added

    use a function node...
    [code] 
        var arr = msg.payload; //store a ref to the array in "arr" temporarily 
        msg.payload = {}; //make msg.payload an (empty) object
        msg.payload.metadata = arr; //store "arr" in msg.payload.metadata
        return msg; //return the msg to next node
        
    [/code]
    
    ↑ deliberately verbose for readability ↑
    
    You can also do this with a change node & probably other ways too.

Then @AxelD said

    Thank you, it worked!

So @system (system) replied

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


{'source': 'discourse', 'url': 'https://discourse.nodered.org/t/help-array-need-to-put-an-array-in-an-array/44922', 'title': 'Help array: need to put an array in an array', 'views': 141, 'has_accepted_answer': True, 'word_count': 123, 'like_count': 0, 'reply_count': 1, 'participant_count': 2, 'posts': 4, 'tags': '', 'author': '@AxelD', 'participants': '@AxelD, @Steve-Mcl (Stephen McLaughlin), @system (system)', 'image_url': ['https://global.discourse-cdn.com/business6/uploads/nodered/original/3X/9/2/92ccc8ee35e1afbbdfaab9d9691ab4288117ae3d.png'], 'created_at': '2021-04-29T09:59:51.627Z', 'last_posted_at': '2021-04-29T10:06:08.368Z'}