Encountering a typeError while attempting to reconstruct another object using double forEach:
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;
})
})
Desired output:
{teacher: {
chemistry: 'newfilesize2MB',
math: 'newfilesize1MB'
},
student: {
chemistry: 'newfilesize3MB',
math: 'newfilesize4MB'
}
}
Any suggestions for fixing this issue?
update
If nested forEach is not feasible, how can I achieve the same result?