0

How can I convert this object

{
    priorities: {
        1: "categoryOne"
        2: "categoryTwo"
    }
}

to this array :

[ {1: "categoryOne"}, {2: "categoryOne"} ]
Tim567
  • 775
  • 1
  • 5
  • 22
hmd.fullstack
  • 478
  • 1
  • 7
  • 20

1 Answers1

2

Take entries of object and then map it:

var obj= { priorities: { 1: "categoryOne", 2: "categoryTwo" }};
var result = Object.entries(obj.priorities).map(([k,v])=>({[k]:v}));

console.log(result);
gorak
  • 5,233
  • 1
  • 7
  • 19