0

I'm building a program in React that is basically a questionnaire / survey, so far I've got users answering a bunch of questions then what I am trying to do is take the answers, filter them a bit then return an object to store using Redux. Each question is an object it self that holds different factors than I am trying to measure. Although, I'm getting stuck with actually trying to create the structure of the final object.

I want the object to look something like this:

Results {
   Question1 {
     factor1: 1,
     factor2: 2,
     factor3: 3
   },
   Question2 {
     factor1: 3,
     factor2: 6
   }, 
   and so on...
}

But when I try create create it by saying for example

let results = {
   Question1 {
      factor1: 0
   }
}

React doesn't like it. As soon as I try nest another object inside it returns an error.. Am I missing something simple or do I need to try another approach, any help would be appreciated

1 Answer 1

2

It should be like this, property and value needs to be separated by a :

let results = {
  Question1 :{
     factor1: 0
  }
}

let Results= {
   Question1: {
     factor1: 1,
     factor2: 2,
     factor3: 3
   },
   Question2: {
     factor1: 3,
     factor2: 6
   }, 
   and so on...
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.