I am struggling with extracting arrays from a simple array of JSON items. Here is the original data:
array = [
{number: 9, item: 'Item 1', descripton: 'abc'},
{number: 5, item: 'Item 2', descripton: 'def'},
{number: 9, item: 'Item 2', descripton: 'ghi'},
{number: 9, item: 'Item 1', descripton: 'xyz'},
]
My goal is to group items based on similar parameters ('number', 'item') and create a new array like below:
array = [
[
{number: 9, item: 'Item 1', descripton: 'abc'},
{number: 9, item: 'Item 1', descripton: 'xyz'},
],
[
{number: 5, item: 'Item 2', descripton: 'def'},
],
[
{number: 9, item: 'Item 2', descripton: 'ghi'},
]
]
I have attempted to use the .sort()
and .filter()
methods, but I have not been able to achieve the desired result.