-1

I have an array of object with keys and values. I want to change that array of object into label value. How can I do this ?

Current Array of object is:

const test = [{
        "value": "ABC",
        "key": "abc"
    },
    {
        "value": "BCD",
        "key": "bcd"
    }
]

Expected Array of object:

const test = [{
        "value": "ABC",
        "label": "abc"
    },
    {
        "value": "BCD",
        "label": "bcd"
    }
]

How can I get expected array of object using current array of object ?

stark
  • 399
  • 2
  • 13
Anurag Mishra
  • 647
  • 3
  • 15
  • 31

1 Answers1

1

const test = [{
    "value": "ABC",
    "key": "abc"
  },
  {
    "value": "BCD",
    "key": "bcd"
  }
]

const output = test.map(item => ({
  value: item.value,
  label: item.key
}));

console.log(output);
wangdev87
  • 8,611
  • 3
  • 8
  • 31