Super simple Array.prototype.map() job
names.map(name => ({ name }))
That is... map each entry (name
) to an object with key "name" and value name
.
var names = [
"Bob",
"Michael",
"Lanny"
];
console.info(names.map(name => ({ name })))
Silly me, I forgot the most important part
names.map(name => name === 'Bob' ? 'Saab' : name)
.map(name => ({ name }))