Having the following input array:
const input = [
{
id: 1,
name: 1
},
{
id: 2,
name: 2
},
{
id: 3,
name: 3
},
{
id: 4,
name: 4
}
];
it must be changed to
output = [
{
id: 1,
name: '1'
},
{
id: 2,
name: '2'
},
{
id: 3,
name: '3'
},
{
id: 4,
name: '4'
}
];
so the value of name to be converted to string. I have found a method to do it but it seems like too complicated:
const output = input.map((el) => ({
...el,
name: el.name.toString()
}));
Is there a better way to do this?