I am successfully getting all the DOM data I require into an object, but am struggeling to get each attribute value (id and value) inserted into the object as separate key:value sets.
So currently I console.log out :
{
mo0: ‘1’,
tu0: ‘1’,
we0: ‘1’, … and so on.
I would like for every iteration to create two key:value sets, using the manual keys fieldId and fieldValue :
fieldId: ‘mo0’, fieldValue: ‘1’
function getTaskData() {
const tasks = document.querySelectorAll('.task')
const obj = {}
tasks.forEach(task => {
const id = task.getAttribute('id');
const value = task.getAttribute('value');
obj[id] = value;
})
console.log(obj);
postJSON(obj);
}
Could anyone help revising the code or point me into the right direction please – I have been stuck on it for hours. Many thanks!!