How can I get this object's values populated, if its keys match the second object's keys?
Object to be populated
const task = {
name: '',
description: '',
status: '',
priority: '',
due_date: '',
due_date_time: '',
parent: '',
time_estimate: '',
start_date: '',
start_date_time: '',
assignees: {},
archived: ''
}
Original Object
const taskData = {
id: '476ky1',
custom_id: null,
name: 'Reunião com o novo Gerente de Vendas - Airton',
text_content: null,
description: null,
status:
{ id: 'p3203621_11svBhbO',
status: 'to do',
color: '#d3d3d3',
orderindex: 0,
type: 'open' },
orderindex: '1.16183176837360000000000000000000',
date_created: '1618317683783',
date_updated: '1618317683783',
date_closed: null,
archived: false,
creator:
{ id: 3184709,
username: 'Michael Jackson',
color: '#455963',
email: '[email protected]',
profilePicture: null },
assignees:
[ { id: 3184709,
username: 'Antonio Santos',
color: '#455963',
initials: 'AS',
email: '[email protected]',
profilePicture: null } ],
watchers:
[ { id: 3184709,
username: 'Antonio Santos',
color: '#455963',
initials: 'AS',
email: '[email protected]',
profilePicture: null } ],
checklists: [],
tags: [],
parent: null,
priority: null,
due_date: null,
start_date: null,
points: null,
time_estimate: null,
time_spent: 0,
custom_fields: [],
dependencies: [],
linked_tasks: [],
team_id: '3101702',
url: 'https://app.clickup.com/t/476ky1',
permission_level: 'create',
list: { id: '13700791', name: 'List', access: true },
project: { id: '7328469', name: 'hidden', hidden: true, access: true },
folder: { id: '7328469', name: 'hidden', hidden: true, access: true },
space: { id: '3203621' },
attachments: []
}
Now, don't condemn me yet, as I'm just starting to deal with objects and I'm sure that there are many ways to do it, but is for loop
an approach to look at? It doesn't modify task
object, right. So how would I go about returning task
populated?
for(let a = 0; a < task.length; a++){
for (let n = 0; n < data.length; a++){
if(Object.keys(task) == Object.keys(data)){
Object.values(task) = Object.values(data)
}
}
}
Appreciate your help!