I have an array of objects like this:
const arrayOfObjects = [
{app: 'User', subpage: 'Dashboard', path: '/user/dashboard'},
{app: 'User', subpage: 'Profile', path: '/user/profile'},
{app: 'User', subpage: 'Settings', path: '/user/settings'},
{app: 'Library', subpage: 'Dashboard', path: '/library/dashboard'},
{app: 'Library', subpage: 'Settings', path: '/library/settings'},
{app: 'Material', subpage: 'Dashboard', path: '/material/dashboard'}]
I want an array of arrays...where each "sub-array" is an array of original objects from arrayOfObjects separated based upon only the app property (User, Library, Material). So, the new array should look like this:
newArray = [
[{app: 'User', subpage: 'Dashboard', path: '/user/dashboard'},
{app: 'User', subpage: 'Profile', path: '/user/profile'},
{app: 'User', subpage: 'Settings', path: '/user/settings'}],
[{app: 'Library', subpage: 'Dashboard', path: '/library/dashboard'},
{app: 'Library', subpage: 'Settings', path: '/library/settings'}],
[{app: 'Material', subpage: 'Dashboard', path: '/material/dashboard'}]
]
I've tried several things with both .map and .forEach, but the best I've done is convert the array of objects to an array of arrays...but without the grouping I need.