Array of Object Manipulation

Hello,

i would like to take Values of Objects in an array (orr), manipulate them and put them with new added Values in a new array(urr) of Objects.

The Code:

let orr = []
let urr = []
let uobj
let obj
var k = 10 
orr = global.get('grml')

for(let i=0;i<k;i++){
    uobj = {}
    obj = {}
    obj.Barcode1 = "A"
    obj.Barcode2 = "B"
    obj.Barcode3 = "C"
    uobj.Barcode4 = obj.Barcode4 
    obj.Quark = "does not taste good"
    obj.NeuerQuark = "Vorhanden"
    uobj.NeueStelle = i
    urr.push(uobj)
}   
const komps = urr;
node.warn(k)
msg.payload = komps
return msg;

I get the new Array of Objects but only with the Value of "NeueStelle".
How do i get Values from Array of Object A to Values in Array of Objects B ?

Greetings
Chorum

What is your input array and the expected output?

urr is my output array, orr is the array with the original data.

originalarrayofobjects

i want to add/change values on the original array.
Changing the Value of Barcode1...4 or add a new one.
i am working on other solutions atm, but nothing works for me ...

when supplying input data it is best to give an example that can be copied and pasted. Then people helping you can then run it against your code to see the issue. There is no need to supply the full data just enogh to use as an example.

The Testflow:
change Array of objects

The Code:

[{"id":"2e074985.05a256","type":"function","z":"a34ad955.984fd","name":"Create Array - > Global","func":"let orr = []\nlet obj\nvar k = 10 \n\n\nfor(let i=0;i<k;i++){\n    obj = {}\n    obj.Stelle = i\n    obj.Barcode1 = 1\n    obj.Barcode2 = 2\n    obj.Barcode3 = 3\n    obj.Barcode4 = 4\n    obj.Quark = \"tastes good\"\n    orr.push(obj)\n}    \nconst komps = orr;\n\n\nnode.warn(k)\nmsg.payload = komps\n\nglobal.set('grml',komps)\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2040,"y":1320,"wires":[["5ef8129a.98433c","a8aa4ccd.f68b3"]]},{"id":"5ef8129a.98433c","type":"function","z":"a34ad955.984fd","name":"Global->array->changed array","func":"let orr = []\nlet urr = []\nlet uobj\nlet obj\nvar k = 10 \norr = global.get('grml')\n\nfor(let i=0;i<k;i++){\n    uobj = {}\n    obj = {}\n    obj.Barcode1 = \"A\"\n    obj.Barcode2 = \"B\"\n    obj.Barcode3 = \"C\"\n    //uobj.Barcode4 = obj.Barcode4 \n    obj.Quark = \"does not taste good\"\n    obj.NeuerQuark = \"Vorhanden\"\n    uobj.NeueStelle = i\n    urr.push(obj&&uobj)\n\n}    \n\nconst komps = urr;\n\n\nnode.warn(k)\nmsg.payload = komps\n\n\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2310,"y":1320,"wires":[["50e56da3.324bb4"]]},{"id":"768d3aa4.92eea4","type":"inject","z":"a34ad955.984fd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1860,"y":1320,"wires":[["2e074985.05a256"]]},{"id":"a8aa4ccd.f68b3","type":"debug","z":"a34ad955.984fd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2230,"y":1360,"wires":[]},{"id":"50e56da3.324bb4","type":"debug","z":"a34ad955.984fd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2530,"y":1320,"wires":[]}]

may be that helps, its a test flow for getting a solution

I found a working solution!

For anyone who wants to know :

[{"id":"2e074985.05a256","type":"function","z":"a34ad955.984fd","name":"Create Array + second Array - > Global","func":"let orr = []\nlet borr = []\nlet obj\nvar k = 10 \n\n\nfor(let i=0;i<k;i++){\n    obj = {}\n    obj.Stelle = i\n    obj.Barcode1 = 1\n    obj.Barcode2 = 2\n    obj.Barcode3 = 3\n    obj.Barcode4 = 4\n    obj.Quark = \"tastes good\"\n    orr.push(obj)\n}    \nconst komps = orr;\n\n\n\n\nfor(let i=0;i<k;i++){\n    obj = {}\n    obj.IamNew = 512+i\n    borr.push(obj)\n}    \n\nglobal.set('grml2',borr)\n\n\n\n\n\n\n\n\n\n\n\nnode.warn(k)\nmsg.payload = komps\n\nglobal.set('grml',komps)\n\n\n\n\n\n\n\n\n\n\n\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2090,"y":1320,"wires":[["5ef8129a.98433c","a8aa4ccd.f68b3"]]},{"id":"5ef8129a.98433c","type":"function","z":"a34ad955.984fd","name":"Global->array->changed array","func":"\n\n\nlet orr = []\nvar k = 10 \norr = global.get('grml')\nlet borr = []\nborr = global.get('grml2')\n\nlet ausgabearray = []\nvar newelement = 1337\n\nfor(let i=0;i<k;i++){\n    \nvar ausgabe = {\n    Stelle: orr[i].Stelle,\n    Barcode1: orr[i].Barcode1,\n    Barcode2: orr[i].Barcode2,\n    Barcode3: orr[i].Barcode3,\n    Barcode4: orr[i].Barcode4,\n    Quark: orr[i].Quark,\n    NewElement: newelement,\n    BorrElement:borr[i].IamNew\n}\nausgabearray.push(ausgabe)\n}\nmsg.payload = ausgabearray\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2410,"y":1320,"wires":[["50e56da3.324bb4"]]},{"id":"768d3aa4.92eea4","type":"inject","z":"a34ad955.984fd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1860,"y":1320,"wires":[["2e074985.05a256"]]},{"id":"a8aa4ccd.f68b3","type":"debug","z":"a34ad955.984fd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2330,"y":1360,"wires":[]},{"id":"50e56da3.324bb4","type":"debug","z":"a34ad955.984fd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2630,"y":1320,"wires":[]}]

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