• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to add data to object

Resolved: How to add data to object

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am trying to adddata from another object into a new object while also adding new data const addCardData = { ...optIn, cardId, cardName} here optIn already has cardId and cardName so they are getting replaced by new values, how to make an addCardData such that cardId and cardName not be replaced but added to the object or as a sub object? or is there any other better way to do this?

Answer:

If your goal is to keep the values from “optIn”, you could add them last.
For example:


If your goal is to add both versions of cardId and both versions of cardName, you have two options:
  1. Change the name of cardId and cardName, since an object can only old one attribute with a given name.

For example:
  1. Add the optIn object as an attribute

Then you can refer to it by addCardData.optIn.cardId.

If you have better answer, please add a comment about this, thank you!

javascript object
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Resolved: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘crm.email’ doesn’t exist (Connection: mysql, SQL: select count(*) as aggregate from `email`

02/04/2023

Resolved: Regex: Curly braces in reverse? Match X characters before a string?

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.