Get values from array of objects using map

const data = [ { amount: ‘100’, user: ‘admin’, date: ‘March 6, 2019’ }, { … Read more Get values from array of objects using map

const data = [
  { amount: '100', user: 'admin', date: 'March 6, 2019' },
  { amount: '120', user: 'admin', date: 'March 6, 2019' },
  { amount: '80',  user: 'admin', date: 'March 7, 2019' },
  { amount: '200', user: 'admin', date: 'March 7, 2019' }
];
const result = data.map(({ amount, user, date }) => [amount, user, date]);

What I pretend is put "amount, user, date" in const keys and get the same result. It is posible?

const keys = "amount, user, date"
const result = data.map(({ keys }) => [keys]);

Source: JavaSript – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *