Add variable with function node

Hello,
I have a function node that return data:
n8n

then, I have an HTTP node wich get the three requests and return looks like:

[
	{
		"order_detail": {
			"id": 106,
			...some other data
		}
	},
		{
		"order_detail": {
			"id": 107,
			...some other data
		}
	},
		{
			"order_detail": {
			"id": 108,
			...some other data
		}
	}
]

I would like to add variable into each order_detail to have something like;

[
	{
		"order_detail": {
			"id": 106,
 			"myVariable": 123,
			...some other data
		}
	},
		{
		"order_detail": {
			"id": 107,
 			"myVariable": 123,
			...some other data
		}
	},
		{
			"order_detail": {
			"id": 108,
 			"myVariable": 123,
			...some other data
		}
	}
]

Just to be sure that I understand you correctly. The Function-Node and its data do actually not matter at all. All you want to do is to add an identical key to each of the order_detail objects that you get as result of the HTTP Request Node?

yes, that’s right.

Then you can use a Function-Node with this code:

return items.map(item => {
  item.json.order_detail.myVariable = 123;
  return item;
});

Here the example workflow:

Thank you @jan
At the opposite, if I want to filter a data and filter every “myVariable: 123” ?

Not sure I understand. Do you want to remove all items which do not have “myVariable” set to 123?

I would like to remove all items “myVariable”.

I assume you mean with ‘item’ → 'property`. In this case the function would look like this:

return items.map(item => {
  delete item.json.order_detail.myVariable;
  return item;
});

Here the example workflow:

thanks a lot.
One last thing (I hope…), how unserialize the data? So start with:

[
	{
		"order_detail": {
			...some data
		}
	},
		{
		"order_detail": {
			...some  data
		}
	},
		{
			"order_detail": {
			...some data
		}
	}
]

and ave this return:

{
	"order_detail": {
		...some data
	}
},
	{
	"order_detail": {
		...some  data
	}
},
	{
		"order_detail": {
		...some data
	}
}

Your output is not valid Javascript Object Notation

Sorry I don’t understand why?

Because the first thing represents an Array. The second is neither an Array nor an Object.

Ok, so to convert data with input like:

    [
	{
		"order_detail": {
			...some data
		}
	},
	]

To output like:

{
    "order_detail": {
    			...some data
    		}
},
return items[0]

Ok, so simple… thank you.