I am currently trying to join to arrays into an array of records, where the two values directly line up as this:
score:
[1,0,43,12]
food:
['ham','cheese','potato','cabbage']
and I would like to create one array as such:
[{food: 'ham', score: 1}, {food: 'cheese', score: 0}, {food: 'potato', score: 43}, {food: 'cabbage', score: 12}]
I can create individual records:
{food: 'ham', score: 1}
{food: 'cheese', score: 0}
etc...
Using this code:
var foodscore = []
for(i in score){
var record = {}
record.food = food[i]
record.score = score[i]
foodscore.push(record)
}
However when I console.log(foodscore) I get:
[Object,Object,Object,Object]
returned, instead of the record. What would be a good solution to this?
EDIT: I forgot to add that this code is part of a function and I would like to return the value of the joined array as above to the value of the function. How do I return the array in its full form, without it outputting [Object,Object,Object,Object]?