Here is a simple printing out of the values of an array:
export default function App() {
var data = [{name:'Jhon', age:28, city:'HO'},
{name:'Onhj', age:82, city:'HN'},
{name:'Nohj', age:41, city:'IT'}
];
data.map(({name, age}, i) => {
console.log(name + ' ' + age);
})
}
Now, I receive the names of the values in another array, how can I print out the values of the array using a variable:
export default function App() {
var data = [{name:'Jhon', age:28, city:'HO'},
{name:'Onhj', age:82, city:'HN'},
{name:'Nohj', age:41, city:'IT'}
];
//Here are the keys of the array
var colNames = ['name','age'];
data.map(({colNames}, i) => {
//So I can do something like
console.log(colNames[0] + ' ' + colNames[1]);
})
}
Thanks!