-2

I'm trying to merge two arrays into one array consisting of objects created from the corresponding array items from the two original arrays:

Ex:

words = ['Toolbar', 'Vamoose', 'Arcade'];

clues = ['Strip of buttons', 'Get lost', 'Pinball wizards hangout'];

What I want:

output = [{'Toolbar', 'Strip of buttons'}, {'Vamoose', 'Get lost'}, {'Arcade', 'Pinball wizards hangout'}]

Any suggestions?

1 Answers1

0

Figured it out:

let words = ['Toolbar', 'Vamoose', 'Arcade'];
let clues = ['Strip of buttons', 'Get lost', 'Pinball wizards hangout'];

let data = [];

words.forEach((obj, index) => {
  obj = {
    word: words[index],
    clue: clues[index]
  };
  data.push(obj)
})

console.log(data)
[{
    "word": "Toolbar",
    "clue": "Strip of buttons"
},
{
    "word": "Vamoose",
    "clue": "Get lost"
},
{
    "word": "Arcade",
    "clue": "Pinball wizards hangout"
}]