I want to construct a new array based on two sets of arrays. My current attempt is:
const mylist = [
{
"city" : "aa",
"country" : "de"
},
{
"city" : "bb",
"country" : "us"
},
{
"city" : "cc",
"country" : "ca"
},
{
"city" : "dd",
"country" : "za"
},
{
"city" : "ee",
"country" : "fr"
},
{
"city" : "ff",
"country" : "gr"
}
]
const stats = [{name : 'original', count: 'one'}, {name: 'copy', count: 'two'}, {name: 'redundant', count: 'three'}];
let myFinalList = [];
let str = 'hello.';
mylist.forEach(function (place, nn) {
let suffix = place.country;
stats.forEach(function (k) {
let items = {};
items[k.name] = str + k.count + '.' + suffix;
items['city'] = place.city;
myFinalList.push(items);
});
}, this);
console.log('print out: ', myFinalList);
the expected result is:
[ { original: 'hello.one.de', copy: 'hello.two.de', redundant: 'hello.three.de', city: 'aa' },
{ original: 'hello.one.us', copy: 'hello.two.us', redundant: 'hello.three.us', city: 'bb' },
...
{ original: 'hello.one.gr', copy: 'hello.two.gr', redundant: 'hello.three.gr', city: 'ff' }]
could somebody help me achieve this goal? i am confused and can't get the right array structure.