-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 ?

0

1 Answer 1

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);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.