How do I convert the script to handle all incoming objects?

Hey all!
I have such a script (see below) for the return of one object.
How should it be converted so that this script will process all objects from the previous node?

let arr = items.map(item => item.json.article_content);
let arr2 = arr[0].split('<p>');
let obj = arr2.reduce((result, item, index, array) => {
        result[index] = {'p': item};
        return result
}, [])
return [{
json: obj
}
]

return [].concat(
  ...items.map(i => i.json.article_content.split('<p>'))
).map(i => ({ json: { p: i } }));

@ivov, hey!
Thank you for your help, your script worked, but not the way I need it (maybe more context should have been provided on my part).
In front of your script, this is the JSON:


After the execution of your script, you get the following result:

Can you upgrade your code so that the “p” breaks occur within (grouped) by “order_id”?
According to this scheme:

[{
		"order_id": "1363419",
		"article_content": [{
				"p": "Paragraph content"
			},
			{
				"p": "Paragraph content"
			}
		]
	},

	{
		"order_id": "1363419",
		"article_content": [{
				"p": "Paragraph content"
			},
			{
				"p": "Paragraph content"
			}
		]
	}
]

I would be very grateful for your help!

function format(str, elem) {
  return str
    .split(`<${elem}>`)
    .filter(Boolean)
    .map(i => ({ [elem]: i.replace(`</${elem}>`, '') }));
}

return items.map(i => ({
    json: {
      order_id: i.json.order_id,
      article_content: format(i.json.article_content, 'p')
    }
  })
);

1 Like

@ivov Thanks!