I have a user with a favorites array
I am trying to concat an item to the favorites field.
Here I assign the user to userToChange variable
const userToChange = action.data.user;
And here I concat a 'card to the user's favorites field
const changedUserFavorites = userToChange.favorites.concat(action.data.card);
I need to pass the updated user field to an axios update call. I have tried to concat the user and the updated favorites field like this.
const changedUser = userToChange.concat(changedUserFavorites);
but I am getting an error: ×
Unhandled Rejection (TypeError): userToChange.concat is not a function
I suspect this might be due to the fact that userToChange is an object
Here is what userToChange looks like:
User to Change
Object
favorites: [Array(1)]
firstName: "phil"
id: "5de9930fedc70846747305f6"
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InBoaWwiLCJmaXJzdE5hbWUiOiJwaGlsIiwiaWF0IjoxNTc1NTkwNDkwfQ.SYoApD4FUuXDEhjWSDBg0_gkKmf7a2FHm5Yifu2yhgw"
username: "phil"
__proto__: Object
and changedUserFavorites is an Array.
Thus, I just wonder how can I put the two together given that one field is an object?
Object.assigncan be your friend..concat()to an object.