Consider the following input array:
const initialArray = [
{
id: 1,
name: 1
},
{
id: 2,
name: 2
},
{
id: 3,
name: 3
},
{
id: 4,
name: 4
}
];
The objective is to modify it to:
updatedArray = [
{
id: 1,
name: '1'
},
{
id: 2,
name: '2'
},
{
id: 3,
name: '3'
},
{
id: 4,
name: '4'
}
];
to convert the value of 'name' to a string. A potential solution involves using the map method but you feel that it may be too complex:
const updatedArray = initialArray.map((element) => ({
...element,
name: element.name.toString()
}));
Are there any simpler alternatives to achieve this transformation?