sort the array and group it with a specific value closed

Consider the following snippet:

// assume arr refers to your array of data
const groups = {}; // for storing groups while processing
arr.forEach(v => {
    if(groups[v.part_image]) 
        groups [v.part_image].push(v.image); // the actual image values you want to group
    else groups[v.part_image] = [ v.image ];
});
// Now you can process each image and all its parts

You can iterate over all the keys in the object. Object.keys(groups) for that.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top