I have this array of objects and I would like to convert it into array of arrays.
const data = [
{
id: 1,
name: ‘Beetlejuice’,
year: ‘1988’,
phone: ‘242342342’
},
{
id: 1,
name: ‘Beetlejuice’,
year: ‘1988’,
phone: ‘242342342’
},
{
id: 1,
name: ‘Beetlejuice’,
year: ‘1988’,
phone: ‘242342342’
},
{
id: 1,
name: ‘Beetlejuice’,
year: ‘1988’,
phone: ‘242342342’
},
];
Object.values
with Array.map
will help to create a new array with each node as the values of each object in the parrent array.
Logic
Array.map
on the input arrayObject.values
of each node of object const data = [{ id: 1, name: 'Beetlejuice', year: '1988', phone: '242342342' }, { id: 1, name: 'Beetlejuice', year: '1988', phone: '242342342' }, { id: 1, name: 'Beetlejuice', year: '1988', phone: '242342342' }, { id: 1, name: 'Beetlejuice', year: '1988', phone: '242342342' }]; const output = data.map(item => Object.values(item)); console.log(output);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.