I have an array of objects:
const users = [
{ name: 'Alice' },
{ name: 'Eve' }
]
However, I want to transform it into an array like this:
const updatedUsers = [
{ key: 'Alice', value: 'Alice', text: 'Alice' },
{ key: 'Eve', value: 'Eve', text: 'Eve' }
]
Currently, I am achieving this using the following method:
const updatedUsers = []
users && users.length > 0 && users.map(user => {
updatedUsers.push({ key: user.name, value: user.name, text: user.name })
})
Is there a simpler way to achieve this transformation without manually building each object and pushing it into a new array?