K.Z
K.Z

Reputation: 5075

iterate json object data using map along with key

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

Upvotes: 0

Views: 51

Answers (1)

Hassan Imam
Hassan Imam

Reputation: 22534

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};
});

Upvotes: 1

Related Questions