After scanning barcodes, I have an array of strings that currently contains the following data:
var array = ['NEW', '1111', 'serial1', 'serial2, 'NEW', '2222', 'serial3', 'serial4'];
To process this scanned data effectively, I need to convert the array into objects structured like this:
var objects = [
{
order_id: '1111',
serial_numbers: ['serial1', 'serial2']
},
{
order_id: '2222',
serial_numbers: ['serial3', 'serial4']
}
]
It is evident that the presence of 'NEW' in the array signifies the upcoming order_id
(e.g. '1111'). Subsequently, there are multiple serial_numbers
listed until the next occurrence of 'NEW'.
My attempt at structuring the array using indexes did not yield satisfactory results.
I appreciate any assistance you can provide!