I have key:value pair as below :
const valueSelection = {
name: string,
colour: string,
design: string,
valueTag: string[],
}
during the run time it becomes as below
const valueSelection = {
name: 'Sam',
colour: 'blue',
design: 'normal',
valueTag: [1, 2]
}
want to convert this into as below
const valueSelection = {
name: 'Sam',
colour: 'blue',
design: 'normal',
valueTag1: 1,
valueTag2: 2
}
How to do this in Reactjs.
Thanks in advance.
You can do something like this :
var newValue = {
...oldValue,
valueTag: undefined,
...(
Object.fromEntries(
oldValue.valueTag.map((val, index) => [`valueTag${index + 1}`, val])
)
)
}