How find properties in an array in object and move these objects to another array in the object? How to extract {"comment": "value"} from this.state.comments
and place it in thecomment
object in the comments
array after other objects?
I remapped the array and extracted the values themselves - comment properties
. How to extract the whole object so it would look like this {"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}`);
Expected effect:
const comment = {
"comments": [{'comment': 'aaa'}, {'comment': 'bbb'},
{"comment": "eeeee"}, {"comment": "rrrrr"}, {"comment":
"ggggg"}, "comment": "hhhhhh"]
"description": " ytytyty"
"id": 3
"title": "gfgfgfgfgf"
}