-1

Input data

const users = [{id: 1, name: 'Madou', age: 37},
  {id: 2, name: 'Fatoumata', age: 33},
  {id: 3, name: 'Amadou', age: 31}];

Output [ [ 1, 'Madou', 37 ], [ 2, 'Fatoumata', 33 ], [ 3, 'Amadou', 31 ] ]

I implemented this:

const _data = users.map((item) => {
  return Object.keys(item).map((value) => item[value]);
});
console.log(_data);

But I want to use REDUCE instead, but I don't have any how to do it

Motra
  • 93
  • 1
  • 7

2 Answers2

2

You can use Array.map() as follows:

const users = [{id: 1, name: 'Madou', age: 37},
  {id: 2, name: 'Fatoumata', age: 33},
  {id: 3, name: 'Amadou', age: 31}];
  
const result = users.map(o => Object.values(o));

console.log(result);
uminder
  • 23,831
  • 5
  • 37
  • 72
0
const _data = users.reduce((acc, { id, name, age }) => {
  acc.push([id, name, age]);
  return acc;
}, []);
  • Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Apr 18 '22 at 10:58