Skip to main content
added 650 characters in body
Source Link

I cann't comment. So i write here!

Are you wanting ...

result = [
    {
        story_id : 25,
        user_id : [10, 12, 15]
    }
]

Right?

This is solution of me

const data = 
    [{notification_id: 124, user_id: 10, story_id: 25, string: "liked on your story" }
     {notification_id: 125, user_id: 12, story_id: 25, string: "liked on your story" }
     {notification_id: 126, user_id: 15, story_id: 25, string: "liked on your story" }]

var result = data.reduce((res, item) => {
    let storyID = item.story_id;
    if (typeof res[storyID] == 'undefined') {
        res[storyID] = {
            story_id: storyID,
            user_id: []
        }
    }
    res[storyID].user_id.push(item.user_id);
    return res;
}, []);

result = Object.values(result);

I cann't comment. So i write here!

Are you wanting ...

result = [
    {
        story_id : 25,
        user_id : [10, 12, 15]
    }
]

Right?

I cann't comment. So i write here!

Are you wanting ...

result = [
    {
        story_id : 25,
        user_id : [10, 12, 15]
    }
]

Right?

This is solution of me

const data = 
    [{notification_id: 124, user_id: 10, story_id: 25, string: "liked on your story" }
     {notification_id: 125, user_id: 12, story_id: 25, string: "liked on your story" }
     {notification_id: 126, user_id: 15, story_id: 25, string: "liked on your story" }]

var result = data.reduce((res, item) => {
    let storyID = item.story_id;
    if (typeof res[storyID] == 'undefined') {
        res[storyID] = {
            story_id: storyID,
            user_id: []
        }
    }
    res[storyID].user_id.push(item.user_id);
    return res;
}, []);

result = Object.values(result);
Source Link

I cann't comment. So i write here!

Are you wanting ...

result = [
    {
        story_id : 25,
        user_id : [10, 12, 15]
    }
]

Right?