I'm looking to combine an array returned from my local Database with dummy data to be sent to the frontend.
I have the two arrays of objects, Users come directly from my mongo database and before I send the result to the frontend, I would like to add the dummy data to the user object array. Now the Users list is a lot larger than my dummy data and thus I would like to loop through my user data and append the dummyData to every user object and once I reach the end of my dummyData, it should just start from the top again.
let users = [
{ name: "John", lastName: "Henry" },
{ name: "Peter", lastName: "Pumpkin" },
{name: "John", lastName: "Snow"},
{name: "Jack", lastName: "Stevens"}
];
let dummyData = [
{
callTime: "Call Now",
userType: "End User(Agent)",
callStatus: "Called",
orderStatus: "Order Placed(1)",
consultant: "Bennie Hennie",
company: "Some Company"
},
{
callTime: "Call Now",
userType: "End User(James Bond)",
callStatus: "Pending Call",
orderStatus: "No Order Placed",
consultant: "Sally Sue",
company: "Super Sonic & Co"
},
{
callTime: "Call Now",
userType: "End User(Peter Griffin))",
callStatus: "Called",
orderStatus: "Order Placed(1)",
consultant: "Jenny Oldstone",
company: "Witcher School"
}
];
The desired end result should be:
users[
{name: "John",
lastName: "Henry",
callTime: "Call Now",
userType: "End User(Agent)",
callStatus: "Called",
orderStatus: "Order Placed(1)",
consultant: "Bennie Hennie",
company: "Some Company"
}]
I think I can achieve this via a forloop, but I've never looped through objects before.