const sendData = result => {
result.centers.forEach(center => {
const data = {
center_id,
name,
address,
district_name,
state_name,
pincode,
fee_type,
sessions
} = center ;
data.sessions = data.sessions.map(session => {
return {
date,
available_capacity,
min_age_limit,
vaccine
} = session ;
})
console.log(data) ;
})
}
why does the above code produce the following error ?
PS: Please ignore the line numbers.
UnhandledPromiseRejectionWarning: TypeError: Assignment to constant variable.
at /home/ubuntu/Projects/Web/CowinTracker/server/app.js:69:17
at Array.map (<anonymous>)
at /home/ubuntu/Projects/Web/CowinTracker/server/app.js:67:39
at Array.forEach (<anonymous>)
at sendData (/home/ubuntu/Projects/Web/CowinTracker/server/app.js:56:20)
I tried changing const data
to let data
and same error occurred.
You can't destructure in your return statement.
You need to either destructure the session argument, or reference the session object and assign the properties to a new object.
If you wanted to destructure the session argument you could do something like this.
})
If you're just cloning the object you could do the following.