-2

I currently have data that is coming back in the following format:

[
[144, '[email protected]', '7358'],
[145, '[email protected], '7358'],
[146, '[email protected], '7359'],

.....


]


I am trying to convert the array of arrays into an array of objects that would look like the following:

[
{employeeId: 144, WorkEmail: '[email protected]',  ClubNumber: '7358'},
{employeeId: 145, WorkEmail: '[email protected]', ClubNumber: '7358'},
{employeeId: 146, WorkEmail: '[email protected]', ClubNumber: '7359'},
]

I am having trouble wrapping my mind around assigning keys to the individual items in each array.

0

1 Answer 1

1

Use Array#map.

let array = [
[144, '[email protected]', '7357'],
[145, '[email protected]', '7358'],
[146, '[email protected]', '7359'],
];

let result = array.map(([employeeId, WorkEmail, ClubNumber]) => ({employeeId, WorkEmail, ClubNumber}))

console.log(result);

Sign up to request clarification or add additional context in comments.

2 Comments

Why not simply array.map(([employeeId, WorkEmail, ClubNumber]) => ({employeeId, WorkEmail, ClubNumber}))?
You are right that's shorter.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.