I have an array inside an object addedCertificates and I want to push values into it.
const addShift = () => {
setShiftList((prev) => [
...prev,
{
id: shiftList.length,
date: '',
startTime: '',
endTime: '',
addedCertificates: [],
selectedCertificate: '',
},
]);
};
When a button click occurs I want to push the selectedCertificate into the addedCertificates array. The function will look something like this:
const addCertificate = (index) => {
const list = [...shiftList];
list[index]['addedCertificates'] = list[index]['selectedCertificate'];
setShiftList(list);
console.log('shiftList from add certificate', shiftList)
}
Right now the addedCertificates just get replaced with the selectedCertificate, but I want to keep the already added certificates. I cant seem to use .push on the array like this:
list[index]['addedCertificates'].push(list[index]['selectedCertificate']);
Does any one know how I can push values to this array?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/FB47m3b
Comments
Post a Comment