【发布时间】:2019-06-13 00:26:52
【问题描述】:
如何在 object 的数组中找到属性并将这些对象移动到 object 中的另一个数组中?如何从this.state.comments 中提取{"comment": "value"} 并将其放在comments 数组中的comment 对象中,位于其他对象之后?
我重新映射了数组并自己提取了值 - comment properties。如何提取整个对象,使其看起来像这样 {"comment:" value "}
const comment = {
"comments": [{'comment': 'aaa'}, {'comment': 'bbb'}]
"description": " ytytyty"
"id": 3
"title": "gfgfgfgfgf"
}
this.state.comments = [
{"comment": "eeeee"},
{"comment": "rrrrr"},
{"comment": "ggggg"},
{"date: Thu Jun 13 2019 01:27:09
"desc": "dfdfdf"
"comment": "hhhhhh"
}
]
let v = this.state.comments.map(t => t.comment? t.comment : t);
console.log(`{comment: ${v}`);
预期效果:
const comment = {
"comments": [{'comment': 'aaa'}, {'comment': 'bbb'},
{"comment": "eeeee"}, {"comment": "rrrrr"}, {"comment":
"ggggg"}, "comment": "hhhhhh"]
"description": " ytytyty"
"id": 3
"title": "gfgfgfgfgf"
}
【问题讨论】:
标签: javascript arrays reactjs ecmascript-6 javascript-objects