Reduce array by key/value in javavascript

Asked

Viewed 36 times

1

How can I reduce the array by grouping it by the key/value and the keys I receive are dynamic?

Input:

[
    {
        "CORAS": "PP007"
    },
    {
        "CORAS": "PP008"
    },
    {
        "COREN": "PP007"
    },
    {
        "COREN": "PP008"
    },
    {
        "COREN": "PP002"
    },
    {
        "COREN": "VNL020"
    },
    {
        "COREN": "VNL121"
    }
]

Output:

{
    "CORAS": ["PP007", "PP008"],
    "COREN": ["PP007", "PP008", "PP002", "VNL020", "VNL121"]
}
  • 1

    What have you tried? See the answers here, the solution is very similar.

  • 1

    You already tried something Tiago?

  • Being the most honest, I did not understand which function I can use to perform this map

  • We’d need to see how you did it to help, edit the question with what you’ve already tried to do, maybe the question will be reopened.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.