I have a variable result
that contains around 1M entries, which looks like this:
result = [
{
'name': 'x',
'other fields': '...',
},
{
'name': 'y',
'other fields': '...',
},
.. and so on ..
]
I want to create another array that only contains a list of names but in object format:
nameArray = [
{name: 'x'},
{name: 'y'},
.. and so on ..
]
I am currently using the following loop, but it is extremely slow for 1M entries
let nameArray = []
result.forEach(item => {
let name = {name : item.name}
nameArray.push(name)
});
What would be the fastest way to achieve this? I also tried lodash maps but still a little slow. But I would prefer not using lodash since it adds one more dependency.