0

I have trying to get collection of data from json object using map and assign key, pair reference in loop but its not working out for me. I can read value in iterations but I need to assign to key and value where I need help. its not recognising "key" and "value"

 var j1 = _preDefineAnswerOptions.map(function(item){
    return ["key": item.preDefineAnswerId, "value": item.text];
 });

data-source structure

enter image description here

2
  • Change return ["key": item.preDefineAnswerId, "value": item.text]; to return {"key": item.preDefineAnswerId, "value": item.text}; Commented Mar 14, 2018 at 13:49
  • thanks it worked... if you paste your answer then I can add plus point on it Commented Mar 14, 2018 at 14:32

1 Answer 1

1

You need to return an object. Use {} around the key and value.

var j1 = _preDefineAnswerOptions.map(function(item){
 return {"key": item.preDefineAnswerId, "value": item.text};
});
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.