I have files stored as an array of objects, each file has a directory. What I need is to have directories stored as an array of objects each containing an array of their files.
How would I process my array to get from this:
[ { local: 'comp_0.mp4', directory: 'video_4', remote: 'http://b6fo00nKJM.mp4', }, { local: 'comp_1.mp4', directory: 'video_4', remote: 'http://J-CgEY_zcL.mp4', }, { local: 'comp_0.mp4', directory: 'video_5', remote: 'http://GHH66-a7eY.mp4', }, { local: 'comp_1.mp4', directory: 'video_5', remote: 'http://ZF0eqIEf5g.mp4', }, ];
To this...
[ { directory: 'video_4', files: [ { local: 'comp_0.mp4', remote:'http://b6fo00nKJM.mp4', }, { local: 'comp_1.mp4', remote:'http://J-CgEY_zcL.mp4', }, ], }, { directory: 'video_5', files: [ { local: 'comp_0.mp4', remote:'http://GHH66-a7eY.mp4', }, { local: 'comp_1.mp4', remote:'http://ZF0eqIEf5g.mp4', }, ], }, ];
https://stackoverflow.com/questions/65386719/group-array-of-objects-by-object-value December 21, 2020 at 10:06AM
没有评论:
发表评论