Basically I have an main object dataToMovie, I have empty arrays. I want to display the content of the arr variable into mov[] and the content of the arr2 into ser[]. I have attempted to do something as you can see. I am looking to do this seperately for each array as I will have multiple data in the future
const dataToMovie = {
createMovie,
links: {
mov: [],
ser: [],
rev: [],
ext: [],
},
};
const dataToInsert1 = {
'model-10389': 164703,
'model-10388': 164704,
'model-10387': 164705,
};
const dataToInsert2 = {
'model-10389': [1656, 1234, 1245],
'model-10384': [1656, 1234, 1245],
'model-10383': [1656, 1234, 1245],
};
const arr = Object.entries(dataToInsert1).map((entry) => ({
id: entry[0].substring(6, entry[0].length),
value: entry[1],
}));
//dataToMovie.links.mov[arr]
const arr2 = Object.entries(dataToInsert2).map(([key, value]) => ({
modelId: key.substring(6),
ids: value,
}));
//dataToMovie.links.ser[arr2]
concat: dataToMovie.links.mov.concat(arr);.push()method to add things to them. You can even immediately push to it inside a foreach loop instead of mapping, if preferred.