I am doing double forEach, but getting a typeError, while trying to reconstruct another object:
const users = [
{teacher: [
{file: 'chemistry', size: '2MB'},
{file: 'math', size: '1MB'}]
}, {student: [
{file: 'chemistry', size: '3MB'},
{file: 'math', size: '4MB'}]
}
];
let final = {};
users.forEach(function(i) {
i.forEach(function(j){
let filesizestring = 'newfilesize'+j.size;
final[j] = j;
final.j[j.file] = filesizestring;
})
})
and the expected result is:
{teacher: {
chemistry: 'newfilesize2MB',
math: 'newfilesize1MB'
},
student: {
chemistry: 'newfilesize3MB',
math: 'newfilesize4MB'
}
}
could somebody help me fix this?
update
if nested forEach is not possible, how can i achieve the same result?
final.j[j.file] = ...- What should this "thing" do? O.o