3

I have this data in a javascript variable:

var a = {
  "answers":[
     {"correct":null, "response":true, "text":"x" },
     {"correct":null, "response":true, "text":"y" }
  ]
}

I would like to send this to the server but exclude the correct and text fields. How can I remove these?

1 Answer 1

7

Try this

var result = a.answers.map(function(obj){return {response:obj.response}})

Here result will be an array of objects having just response field.

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

1 Comment

Thanks. I did try map but now I realize I probably did not do it correctly. I will try your suggestion.

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.