-4

How to convert:

[
    {
        "tag":"google",
        "count":1
    },
    {
        "tag":"microsoft",
        "count":2
    }
]

to something like:

{
    "google":1,
    "microsoft":2
} 

in typescript using built in function or any shortcut?

dedman
  • 868
  • 6
  • 16

1 Answers1

-2
var arr=[
    {
        "tag":"google",
        "count":1
    },
    {
        "tag":"microsoft",
        "count":2
    }
];
var k=arr.reduce((a, { tag, count }) => Object.assign(a, { [tag]: count }), {});
console.log(k);

CertainPerformnce meant this.

Praveen Ojha
  • 1,161
  • 1
  • 14
  • 22