我在javascript变量中有这些数据:
var a = {
"answers":[
{"correct":null, "response":true, "text":"x" },
{"correct":null, "response":true, "text":"y" }
]
}
Run Code Online (Sandbox Code Playgroud)
我想将此发送到服务器但排除correct和text字段.我怎样才能删除这些?
试试这个
var result = a.answers.map(function(obj){return {response:obj.response}})
Run Code Online (Sandbox Code Playgroud)
这里result将是一个只有response字段的对象数组.