I have an array of objects:
const dataset = [
{name: 'Marie', year: 12, country: 'Canada'},
{name: 'Jeff', year: 18, country: 'France'},
{name: 'Joss', year: 10, country: 'Spain'},
{name: 'Carrie', year: 45, country: 'Belgium'},
{name: 'Linda', year: 32, country: 'France'},
]
I want two array: one with names and one with countries:
const names = ['Marie', 'Jeff', 'Joss', 'Carrie', 'Linda']
const countries = ['Canada', 'France', 'Spain', 'Belgium', 'France']
So, I usually do:
const names = dataset.map(e => e.name)
const countries = dataset.map(e => e.country)
Is there a simplest way possibly using a single loop?